Magento2 SEO – Remove Keywords Meta Tag from Head

magento2seo

It seems like having a keywords meta tag in your head is nowadays bad for SEO. Does anyone know how to remove the keywords meta tag from the head in Magento 2 in a professional way?

Best Answer

Create a module with name STech_Removekeywords and create the files like below steps:

Step 1: Create registration.php under:

app/code/STech/Removekeywords/registration.php

with below content:

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'STech_Removekeywords',
    __DIR__
);

Step 2: Create module.xml under:

app/code/STech/Removekeywords/etc/module.xml

with below content:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="STech_Removekeywords" setup_version="0.0.1">
        <sequence>
            <module name="Magento_Backend"/>
            <module name="Magento_Sales"/>
            <module name="Magento_Catalog"/>
        </sequence>
    </module>
</config>

Step 3: Create di.xml under:

app/code/STech/Removekeywords/etc/di.xml

with below content:

<?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="STech\Removekeywords\Plugin\PageConfig\RemoveMetaKeywords" sortOrder="9999"/>
    </type>
</config>

Step 4: Create RemoveMetaKeywords.php under:

app/code/STech/Removekeywords/Plugin/PageConfig/RemoveMetaKeywords.php

with below content:

<?php
namespace STech\Removekeywords\Plugin\PageConfig;

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

Run setup upgrade, di compile and other required commands and test.