Category page layout meta update - add og:image [closed]
-
12-12-2019 - |
Question
Can I update layout at category page to add og:image tag? I need to use special image as og:image, not category image nor thumbnail image.
Thanks
Solution
You can add the following to your local.xml file:
<catalog_category_default>
<reference name="head">
<block type="core/template" name="og" as="og" template="og/category.phtml" />
</reference>
</catalog_category_default>
Now you need to create the file under og/category.phtml inside you theme (app/design/frontend/{your_package}/{your_theme}/template/og/category.phtml) with the following content:
<?php $_category = Mage::registry('current_category'); ?>
<?php if ($_category) : ?>
<meta property="og:url" content="<?php echo "http://". $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];?>"/>
<meta property="og:description" content="<?php echo htmlspecialchars($_category->getDescription())?>"/>
<meta property="og:title" content="<?php echo htmlspecialchars($_category->getName())?>"/>
<meta property="og:image" content="<?php echo $_category->getImageUrl()?>"/>
Hope it helps!
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange