Getting rid of tags in the meta description of product pages in Magento?

magento

Solution

The `meta` tags are rendered in the template `app/design/frontend/{interface}/{theme}/template/page/html/head.phtml` like this:

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

I think you can replace `htmlspecialchars` with `strip_tags`. You will probably get a better value for these tags. What I don't understand is, how does this happen to you. The products have separated fields for entering meta description and keywords, that do not use a WYSIWYG editor. If you use some kind of automated filling of these fields from the product description maybe it would be a good idea to strip the tags before filling in the fields. [EDIT] You can try to replace the tags with spaces instead of stripping them:

$description = preg_replace('#<[^>]+>#', ' ', $this->getDescription());

then you can remove the double spaces

$description = preg_replace('!\s+!', ' ', $description);

Problem

We are using the WYSIWYG editor for product descriptions and there are HTML tags in them. However Magento is using everything as they are in the meta content description in the header of the product pages which makes it ugly when people are sharing the page on social networks because the description is comprised of raw HTML tags. For example, on this page, the meta description looks like this: ``` <meta name="description" content="&lt;div class=&quot;short-description&quot;&gt; &lt;div class=&quot;std&quot;&gt; &lt;ul&gt; &lt;li&gt;Colored bridesmaid dress made in lace and taffeta&lt;/li&gt; &lt;li&gt;The top is made of ivory French corded lace, the skirt is made of colored taffeta&lt;/li&gt; &lt;li&gt;Straight front neckline, V Back&lt;/li&gt; &lt;li" /> ``` My question is how I can get rid of the tags so only the text are used in the description? I don't know which template to look. Any help would be appreciated! Thanks!

Original source