Optimiser Magento pour Google et les réseaux sociaux à l'aide de Rich Snippets

Rich Snippets va vous aider à optimiser votre référencement et vos partages sur réseaux sociaux en ajoutant en entête de page de multiples indications.

Il faut commencer par ouvrir le fichier app/design/frontend/default/VotreTheme/template/page/html/head.php pour y ajouter la ligne :

<?php echo $this->getChildHtml('rich-snippets'); ?>

qui se chargera d'appeler un fichier rich-snippets.phtml que nous allons créer.

Puis, dans le fichier app/design/frontend/default/VotreTheme/layout/local.xml, il faut trouver le paragraphe :

<reference name="head">
...
</reference>

pour y ajouter la ligne :

<block type="core/template" name="rich.snippets" template="page/html/header/rich-snippets.phtml" />

Enfin, il faut créer le fichier app/design/frontend/default/VotreTheme/template/page/html/header/rich-snippets.php :

<?php
/**
 *
 * Copyright (c) 2013 Studio Boz
 *
 * @project_name Studio Boz
 * @copyright    Copyright (c) 2013 Studio Boz (http://studioboz.com.br)
 * @author       Rick Benetti <Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.>
 *
 **/
 ?>

<?php
    $_storeId = Mage::app()->getStore()->getId();
    $_helper = $this->helper('catalog/output');
    $product  = Mage::registry('product');
    //$productUrl = $product->getUrlModel()->getUrl($product, array('_ignore_category' => true));
    $currency = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
    $_twitter_username = Mage::getModel('core/variable')->setStoreId($_storeId)->loadByCode('twitter_username')->getValue('plain');
    if ($product):
    $productUrl = $product->getProductUrl();
?>
    <meta itemprop="url" content="<?php echo $productUrl; ?>" />
    <meta itemprop="sku" content="<?php echo $product->getSku() ?>" />
    <meta itemprop="price" content="<?php echo number_format($product->getPrice(), 2);?>" />
    <meta itemprop="priceCurrency" content="<?php echo Mage::app()->getStore()->getCurrentCurrencyCode();?>" />
<?php if ($this->getReviewsCount()) : ?>
    <meta itemprop="ratingValue" content="<?php echo $product->getRatingSummary(); ?>"/>
    <meta itemprop="reviewCount" content="<?php echo $product->getReviewsCount(); ?>" />
    <meta itemprop="bestRating" content="100"/>
    <meta itemprop="worstRating" content="0"/>
<?php endif; ?>
    <!-- Facebook - Open Graph -->
    <meta property="og:title" content="<?php echo Mage::app()->getWebsite()->getName(); ?>" />
    <meta property="og:type" content="product" />
    <meta property="og:url" content="<?php echo $productUrl; ?>" />
    <meta property="og:price:amount" content="<?php echo Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), true); ?>" />
    <meta property="og:price:currency" content="<?php echo Mage::app()->getStore()->getCurrentCurrencyCode() ?>" />
    <meta property="og:image" content="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize(996,1490); ?>" />
    <meta property="og:description" content="<?php echo strip_tags($product->getShortDescription()); ?>" />
    <meta property="og:site_name" content="<?php echo Mage::app()->getWebsite()->getName(); ?>" />
    <!-- Twitter - Card -->
     <meta name="twitter:site" content="@<?php echo $_twiter_username; ?>" />
     <meta name="twitter:card" content="product">
     <meta name="twitter:url" content="<?php echo $productUrl; ?>">
     <meta name="twitter:title" content="<?php echo Mage::app()->getWebsite()->getName(); ?>">
     <meta name="twitter:description" content="<?php echo strip_tags($product->getShortDescription()); ?>">
     <meta name="twitter:image" content="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize(996,1490); ?>" />
     <!-- Google Plus -->
     <meta itemprop="description" content="<?php echo strip_tags($product->getShortDescription()); ?>">
     <meta itemprop="image" content="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize(996,1490); ?>" />
     <meta itemprop="name" content="<?php echo Mage::app()->getWebsite()->getName(); ?>">
     <meta itemprop="url" content="<?php echo $this->helper('catalog/product')->getProductUrl($product); ?>">


<?php else: ?>
    <!-- Facebook - Open Graph -->
    <meta property="og:title" content="<?php echo $this->getLayout()->getBlock('head')->getTitle() .' « '. Mage::app()->getWebsite()->getName(); ?>" />
    <meta property="og:type" content="store" />
    <meta property="og:url" content="<?php echo Mage::helper('core/url')->getCurrentUrl();?>" />
    <meta property="og:image" content="<?php echo $this->getSkinUrl('images/logo.png') ?>" />
    <meta property="og:description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />
    <meta property="og:site_name" content="<?php echo Mage::app()->getWebsite()->getName(); ?>" />

    <!-- Twitter - Card -->
     <meta name="twitter:site" content="@<?php echo $_twitter_username; ?>" />
     <meta name="twitter:card" content="summary">
     <meta name="twitter:url" content="<?php echo Mage::helper('core/url')->getCurrentUrl();?>">
     <meta name="twitter:title" content="<?php echo $this->getLayout()->getBlock('head')->getTitle() .' « '. Mage::app()->getWebsite()->getName(); ?>">
     <meta name="twitter:description" content="<?php echo htmlspecialchars($this->getDescription()) ?>">
     <meta name="twitter:image" content="<?php echo $this->getSkinUrl('images/logo.png') ?>">

     <!-- Google Plus -->
     <meta itemprop="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>">
     <meta itemprop="image" content="<?php echo $this->getSkinUrl('images/logo.png') ?>">
     <meta itemprop="name" content="<?php echo Mage::app()->getWebsite()->getName(); ?>">
     <meta itemprop="url" content="<?php echo Mage::helper('core/url')->getCurrentUrl();?>">
<?php endif; ?>

Il est à noter de vérifier régulièrement le code source de la page en cas de mise à jour majeure dans les systèmes d'indexation Google, ou de partage des réseaux sociaux.

Ce tuto a été testé sur Magento ver. 1.9.1.0.

Source : Studio Boz (http://studioboz.com.br)

BLOG COMMENTS POWERED BY DISQUS