Yoast / Yoast-SEO-for-Magento2

Yoast SEO for Magento 2
Other
70 stars 28 forks source link

Tags are not stripped from og:description #62

Closed peterjaap closed 6 years ago

peterjaap commented 6 years ago

So we get stuff like this;

image

... etc

Because the HTML is closed, the actual text shows on top of the page.

We now have overriden vendor/maxserv/magento-module-yoastseo/view/frontend/templates/yoastseo.phtml in our theme and changed;

<meta property="og:description" content="<?php echo $meta->getOpenGraphDescription(); ?>"/>

to;

<meta property="og:description" content="<?= $block->escapeHtmlAttr($block->stripTags($meta->getOpenGraphDescription())) ?>"/>

peterjaap commented 6 years ago

That produced ugly output. Better yet, we created plugins for the three MetaProviders that return nice output. One example;

<?php

namespace Elgentos\FixYoastSeo\Plugin\Product;

class MetaProviderPlugin
{
    public function afterGetOpenGraphDescription(\MaxServ\YoastSeo\Model\EntityConfiguration\Catalog\Product\MetaProvider $subject, $result)
    {
        return trim(preg_replace('#<[^>]+>#', ' ', $result));
    }
}
vincenthornikx commented 6 years ago

issue has been fixed in 2.0.0