I want to add custom script just after the start of head tag. I want to do that because if i add my customer script using
i tried to add code in default_head_blocks.xml
<referenceContainer name="head.additional"> <block class="Custom\Module\Block\Success" template="Custom_Module::success/head.phtml"/> </referenceContainer> Output: <script>console.log("I'm loaded!");</script> </head>
Header.additional add script before the end of head tag while i want to add the script just after the starting <head> tag.
I want to do that because I am using third part Js which is generating Mismatch error with require.js did follow the steps to prevent the mismatch but no solution.
So we did a trick to load that script before the require.js and just after the starting <head> tag.
Any help would be appreciated.
Solved! Go to Solution.
You need to use script tag with below way like,
you cant directly call script with console in your xml file.
Thanks rakesh but i did try that as well but it adds it after the require.js file. Reason why i want to load my custom third party script code before require.js because it's giving mismatch error.
Did try the solutions mentioned by require.js which doesn't work as well so though to add it before require.js call which worked fine.
Solution someone explained here worked for me; https://stackoverflow.com/questions/48167553/magento-2-add-custom-script-just-after-head-tag