Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add facebook og:meta tags in LAYOUT.xml in magento?

I want to insert Facebook og:meta tags to use for facebook sharer ,in a head of a particular page and this page is not a CMS page.I am thinking of adding these tags through that extension layout file. I know normal titles and description are added like this ->

<reference name="head">
        <action method="setTitle"><title>My Module Page</title></action>   
 </reference>

Does magento provides something like this for Facbook og:meta tags?If not ,what is/are the other method to put og:meta tags in the head of a page so that it work with facebook sharer.

like image 956
akt Avatar asked Nov 30 '22 14:11

akt


2 Answers

<reference name="head">
    <block type="core/text" name="blockname">
        <action method="setText">
            <text>
                <![CDATA[<meta property="og:image" content="http://example.com/image.jpg"/>]]>
            </text>
        </action>
    </block>
</reference>
like image 124
Alexandru Bangală Avatar answered Dec 05 '22 20:12

Alexandru Bangală


Magento doesn't include an action to include these meta tags. Instead, you could create a template file (/app/design/frontend/mypackage/mytheme/page/html/facebookmeta.phtml) with your meta tags in it.

Then, add the following to your head reference:

<block type="core/template" name="facebookmeta" template="page/html/facebookmeta.phtml" />

Clear your caches and you should see your block being included into the head for that particular page. It's not a particularly extendable solution, if you want to pass options to this template you should really create a new block, which requires creating a new module etc.

However, in your template file you can use PHP, so you should be able to get various variables you need, for example:

<meta property="og:site_name" content="<?php echo Mage::app()->getStore()->getName() ?>"/>

Hope this helps.

like image 21
Joe_Qip Avatar answered Dec 05 '22 20:12

Joe_Qip