Magento 2 Footer – How to Add Footer Block to All Pages

blockscms-pagesfootermagento2

I have been had a little problems by customizing luma's default footer, for that, I decided to delete it and in its place add a new block that i created in the admin.

I deleted the footer (not entirely, I left the copyright bar) via XML by doing

<referenceContainer name="footer" remove="true"/>

and created its substitute via admin, in where i added it to my home.

I want the block to be in all the pages as my old footer was.
What can i do?

Best Answer

I thing you don't need to delete footer file. Just override footer file app/design/frontend/Vendor/ThemeName/Magento_Theme/layout/default.xml or in your luma theme with this content:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="footer-container">
            <block class="Magento\Theme\Block\Html\Footer" name="footer" template="html/footer.phtml"/>
        </referenceContainer>
    </body>
</page>

And call your static block in ../templates/html/footer.phtml file.

echo $this->getLayout()
          ->createBlock('Magento\Cms\Block\Block')
          ->setBlockId('your_block_identifier')
          ->toHtml();

Now your block content displayed in all pages

Also using this method you can do your other customization like calling newsletter, get default footer link and custom php codes as per your requirements.

Related Topic