在Magento中去掉产品页面元描述中的标签?

在Magento中去掉产品页面元描述中的标签?,magento,Magento,我们使用所见即所得编辑器进行产品描述,其中包含HTML标记。然而,Magento正在使用产品页面标题中的元内容描述中的所有内容,这使得人们在社交网络上共享页面时变得丑陋,因为描述由原始HTML标记组成 例如,在上,元描述如下所示: <meta name="description" content="&lt;div class=&quot;short-description&quot;&gt; &lt;div class=&quot;std&a

我们使用所见即所得编辑器进行产品描述,其中包含HTML标记。然而,Magento正在使用产品页面标题中的元内容描述中的所有内容,这使得人们在社交网络上共享页面时变得丑陋,因为描述由原始HTML标记组成

例如,在上,元描述如下所示:

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


我的问题是如何去掉标记,以便在描述中只使用文本?我不知道该看哪个模板。任何帮助都将不胜感激!谢谢

在模板
app/design/frontend/{interface}/{theme}/template/page/html/head.phtml中呈现
meta
标记,如下所示:

<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" />
<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />
<meta name="keywords" content="<?php echo htmlspecialchars($this->getKeywords()) ?>" />
然后可以删除双空格

$description = preg_replace('!\s+!', ' ', $description);
复制此文件

/app/code/core/Mage/Catalog/Block/Product/View.php
在此文件夹中(在此之前创建!)

现在查找此代码(Magento 1.9.1.0中的第67行)

然后像编辑一样编辑它

$description = $product->getMetaDescription();
            if ($description) {
                $headBlock->setDescription( ($description) );
            } else {
                $strippeddesc = html_entity_decode(strip_tags($product->getDescription()));
                $headBlock->setDescription(Mage::helper('core/string')->substr($strippeddesc, 0, 255));
            }
我添加了一个$strippeddesc,其中包含产品描述的内容,已清理并正确解码


现在我们可以在谷歌上看到一些精彩的metadesc;-)

我们需要在产品描述中使用ul列表或ol列表。我们直接从Magento后端控制台目录->管理产品添加/编辑产品。还有更好的方法吗?在最后的php echo中,我使用了html_实体解码so&;不会像这样获得输出
echo html\u entity\u decode($description)
$description = $product->getMetaDescription();
            if ($description) {
                $headBlock->setDescription( ($description) );
            } else {
                $strippeddesc = html_entity_decode(strip_tags($product->getDescription()));
                $headBlock->setDescription(Mage::helper('core/string')->substr($strippeddesc, 0, 255));
            }