Skip to main content
Return empty string. Type-casting null to a string just returns an empty string anyway
Source Link

I just had to do the same and decided to just add a plugin after the getKeywords Method of the page config which returns a nullan 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 (string)null;'';
    }
}

I just had to do the same and decided to just add a plugin after the getKeywords Method of the page config which returns a null 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 (string)null;
    }
}

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 '';
    }
}
Source Link
David Verholen
  • 6.3k
  • 1
  • 20
  • 38

I just had to do the same and decided to just add a plugin after the getKeywords Method of the page config which returns a null 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 (string)null;
    }
}