Magento 2 | Add Magento Newsletter form in footer ( or where you need )
I need to add a newsletter form in footer of our Magento store:
Something like this :
First of all, login to backend and navigate to : “Content => Blocks” and add a new block.
Compile the block in all his parts , this is mine:
And in the content area add :
<h2>NEWSLETTER & SOCIAL</h2> {{block class="Magento\Newsletter\Block\Subscribe" name="static.newsletter" template="Magento_Newsletter::subscribe.phtml"}}
Basically the code is composed by a title ( the
<h2></h2>
) and the code for call the newsletter .phtml file.
Next step is to add the newsletter’s block to the footer.
Let’s open “footer.phtml” from “App => Design => frontend =>your theme directory=> Magento_Theme => templates => html “, and, where you want the newsletter appears, add this code:
<!-- Newsletter Column --> <?php echo '<div class="newsletter_wrp">'; echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('footer_newsletter')->toHtml(); echo '</div>'; ?>
Empty all caches, reload a page with footer, and, if all it’s right, you see a newsletter form in footer.
Now we need to override the default newsletter form, so, navigate to “App => Magento => Newsletter => Frontend => Template => Subscribe.phtml” and copy and paste in “App => Design => frontend =>your theme directory=> Magento_Newsletter => templates => subscribe.phtml”.
We can edit the file in the way we need.
Save, empty all caches, reload, and, if all it’s right, you’ll see the modified template in the footer.
That’s all