Add .phtml file on all pages magento 2

Add this code in the your custom theme in default.xml: (app/design/frontend/Namespace/Themename/Magento_Theme/layout/default.xml)

<referenceContainer name="after.body.start">
      <block class="Magento\Framework\View\Element\Template" name="custom.file" before="-" template="Magento_Theme::html/custom.phtml" />
</referenceContainer>

Comments