Magento 2 – Remove Meta Keywords from All Pages

magento2seo

I'm currently developing some Magento2 themes. I noticed that in Magento2 Meta Keywords are still added. I want to remove this meta keywords from all pages, does anyone know the proper way to achieve this?

I did find meta.phtml, but I think this file is not used on a product page. Also the file Product/View.php adds the keywords with this function:

$this->pageConfig->setKeywords($keyword);

but I don't think it would be the prober way to extend the _prepareLayout function, right?

Thanks.

Best Answer

I just had to do the same and decided to just add a plugin after the getKeywords Method of the page config which returns an empty string. works great

di.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\View\Page\Config">
        <plugin name="removeMetaKeywords" type="Vendor\Module\Plugin\PageConfig\RemoveMetaKeywords" sortOrder="9999"/>
    </type>
</config>

Plugin Class:

<?php
declare(strict_types = 1);
namespace Vendor\Module\Plugin\PageConfig;

class RemoveMetaKeywords
{
    public function afterGetKeywords($subject, string $return)
    {
        return '';
    }
}