I am trying to create dynamic head using phtml on Magento 2.3.5 p1.

I am inserting in default.xml the following:

 <referenceContainer name="head.additional">
        <block class="Magento\Framework\View\Element\Template" name="custom_head_file" template="Magento_Theme::custom_head.phtml"/>

The output of custom_head.phtml is showing inside the BODY and not inside the HEAD.

Any ideas on how can this be debugged and corrected? I also tried refereceBlock and the result is the same.

  • I just try your code and it is correct and phtml connect showing just before </head>
    – Pawan
    Commented Dec 29, 2020 at 3:02
  • Please make sure your default.xml is being processed by Magento Commented Dec 29, 2020 at 6:58

1 Answer 1


My bad. The problem was not in the default.xml, but in the content in the custom_head.phtml.

I had originally

echo "testing";

Once i changed the content of custom_head.phtml as shown under it works.

echo "<link rel='dns-prefetch' href='//www.google.com/'>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.