Magento 2 – How to Add Social Links in Footer

layoutmagento2social-buttonsxml

I was trying to do something like this in my theme folder's default.xml

<referenceBlock name="footer_social_links">
    <block class="Magento\Framework\View\Element\Html\Link" name="social.link" after="">
    <arguments>
        <argument name="label" xsi:type="string" translate="true">Contact Us</argument>
        <argument name="class" xsi:type="string" translate="false">contact</argument>
        <argument name="path" xsi:type="string">contact</argument>
    </arguments>
    </block>
</referenceBlock>

It isn't working at the moment. What I'm wanting to do is add some facebook icon and twitter icon linking to a specific page (pretty normal?).
I couldn't find other answers on the stackexchange here for Magento 2.

This was using XML code. Do I need to do in PHTML? I changed the "footer_links" to add custom links already with XML so I thought this was very similar that it would also be done in XML.

Footer Appearance

I want to add it along the right, under the subscribe section. How do I implement, and then where do I put the styles? _theme.less only and it links by just the class name?

Best Answer

Have you already added the footer_social_links block? referenceBlock should only be used with already defined blocks. If you haven't already created this block you'll need to add it using block instead of referenceBlock.


Personally I would add a template with your social media links/icons, then call this template within the XML. Like so:

<referenceBlock name="footer_social_links">
     <block class="Magento\Framework\View\Element\Template" name="social.link" template="Magento_Theme::social-links.phtml" before="-"/>
</referenceBlock>

This creates a block within footer_social_links, this block uses the template in Magento_Theme/templates/social-links.phtml - Here you can add your content.

If this doesn't work then check that the block footer_social_links is displaying correctly.

Related Topic