logo

We’re like the in-house digital marketing and web development team you always dreamed of, able to tell your story like nobody else, and focus on your bottom line along with you..

Birmingham office:
+44 (0)121 288 3449

 

Amsterdam office:
+31 (0)20 8932923

 

nina@elancreative.studio

Add Open Graph Meta Data Tags in Magento - Elan Creative
3594
post-template-default,single,single-post,postid-3594,single-format-standard,qode-core-1.3,ctcc-exclude-AN,ajax_fade,page_not_loaded,,pitch child-child-ver-1.0.0,pitch-ver-2.3, vertical_menu_with_scroll,smooth_scroll,side_menu_slide_from_right,grid_1300,blog_installed,wpb-js-composer js-comp-ver-6.3.0,vc_responsive

Add Open Graph Meta Data Tags in Magento

This FAQ will show you how to quickly add OG or Open Graph data to your Magento product pages. It involves editing just one of  your template files.

  1. Go to app/design/frontend/default/YOURTHEME/template/page/html/head.phtml
  2. Add this code snippet below into this file. This code can go anywhere in the file but we usually put it before Magento outputs the theme CSS files, so before this line <?php echo $this->getCssJsHtml() ?>

<?php /* Open Graph Protocol for Facebook and SEO START */ ?> <?php if(Mage::registry(‘current_product’)): ?> <?php $product = Mage::registry(‘current_product’); ?> <meta property=”og:title” content=”<?php echo ($product->getName()); ?>” /> <meta property=”og:type” content=”product” /> <meta property=”og:image” content=”<?php echo $this->helper(‘catalog/image’)->init($product, ‘small_image’)->resize(200,200);?>” /> <meta property=”og:url” content=”<?php echo Mage::registry(‘product’)->getProductUrl(); ?>” /> <meta property=”og:description” content=”<?php echo strip_tags(($product->getShortDescription())); ?>” /> <meta property=”og:site_name” content=”<?php echo Mage::app()->getStore()->getName(); ?>” /> <?php elseif(Mage::registry(‘current_category’)): ?> <meta property=”og:title” content=”<?php echo $this->getTitle() ?>” /> <meta property=”og:type” content=”product.group” /> <meta property=”og:url” content=”<?php echo $this->helper(‘core/url’)->getCurrentUrl();?>” /> <meta property=”og:description” content=”<?php echo strip_tags($this->getDescription()) ?>” /> <meta property=”og:site_name” content=”<?php echo Mage::app()->getStore()->getName(); ?>” /> <?php elseif((Mage::getSingleton(‘cms/page’)->getIdentifier() == ‘home’ && Mage::app()->getFrontController()->getRequest()->getRouteName() == ‘cms’)) : ?> <meta property=”og:title” content=”<?php echo $this->getTitle() ?>” /> <meta property=”og:type” content=”website” /> <meta property=”og:url” content=”<?php echo $this->helper(‘core/url’)->getCurrentUrl();?>” /> <meta property=”og:description” content=”<?php echo strip_tags($this->getDescription()) ?>” /> <meta property=”og:site_name” content=”<?php echo Mage::app()->getStore()->getName(); ?>” /> <?php else: ?> <meta property=”og:title” content=”<?php echo $this->getTitle() ?>” /> <meta property=”og:type” content=”article” /> <meta property=”og:url” content=”<?php echo $this->helper(‘core/url’)->getCurrentUrl();?>” /> <meta property=”og:description” content=”<?php echo strip_tags($this->getDescription()) ?>” /> <meta property=”og:site_name” content=”<?php echo Mage::app()->getStore()->getName(); ?>” /> <?php endif; ?> <?php /* Open Graph Protocol for Facebook and SEO END */ ?>

Thanks to the guys over at Nailed It Design for this FAQ.

Nina Young About the author

I studied mathematics at university, taught myself software development, honed my skills with multinational companies such as IBM and have set up and sold my own businesses. My perspective covers the all important period when a business moves from small and successful to substantial and market-leading, and my personal experience allows me to provide online solutions that give business leaders mastery of their online presence and control over business development.

No Comments

Leave a Comment: