2

In the header I have the following code for meta description.

<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />

I am trying to get this description as my schema product description as follows in the view.pthml file

<meta itemprop="description" name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" /> 

However "Description" it shows up as a blank on the google rich snippets tool.

When I enclose

<meta itemprop="description" name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />

with a <span itemscope itemtype="Http://Schema.Org/Product" > it shows up, but of course breaks the other product itemtype thats on the page.

So how do I get the description in the header to show as my schema product description?

Note: the default meta description is not used (blank) a extension called creare SEO creates the meta description based on attributes.

3
if(Mage::registry('current_product')){
Mage::registry('current_product')->getDescription();
}

instead of $this->getDescription() ;

Hi,In product page $this->getDescription() function logic depend on below logic

$description = $product->getMetaDescription();
            if ($description) {
                $headBlock->setDescription( ($description) );
            } else {
                $headBlock->setDescription(Mage::helper('core/string')->substr($product->getDescription(), 0, 255));
            }

this Code is exiting on fileapp/code/Mage/Catalog/Block/Product/View.php .If you have any issue change logic here.it maay you data issue

Just put code in view.phtml

<?php 
 $description='';
 $description = $_product->getMetaDescription();
            if ($_product->getMetaDescription()) {
               $description=$_product->getMetaDescription();
            } else {
                $description=Mage::helper('core/string')->substr($_product->getDescription(), 0, 255);
            }
?>
<meta itemprop="description" name="description" content="<?php echo htmlspecialchars($description) ?>" />

after

  <?php $_product = $this->getProduct(); ?>

Last resolution:

<?php $headBlock = $this->getLayout()->getBlock('head'); echo $description=$headBlock->getDescription(); ?>" />
  • so it will be like this <meta itemprop="description" name="description" content="<?php echo htmlspecialchars if(Mage::registry('current_product')){ Mage::registry('current_product')->getDescription();} ?>" /> – user2240778 Aug 7 '14 at 14:53
  • yes.also put else conditions – Amit Bera Aug 7 '14 at 14:54
  • it is only works for product page – Amit Bera Aug 7 '14 at 14:54
  • sorry what will be the actual code? this is what I have <meta itemprop="description" name="description" content="<?php echo htmlspecialchars if(Mage::registry('current_product')){ Mage::registry('current_product')->getDescription();} ?>" /> – user2240778 Aug 7 '14 at 14:56
  • the view.phtml file i'm talking about is app/design/frontend/[package]/[theme]/template/catalog/product/view.phtml – user2240778 Aug 7 '14 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.