I need to create a custom module that allows excluding/skipping the Products, Categories and CMS Pages URLs from generating in sitemap.xml. I had tried this solution for Magento 1, How could I do it in Magento 2?

1 Answer 1


Answer given a base on Magento 2.3.1 Opensource

There are 3 files, the Sitemap related data of Products, Categories, and CMS Pages is coming




So, you want to skip any product/category/page from sitemap.xml you have to work on that related class and its method.

So, create plugin on required classes and changes the out of that required getCollection() method.

Or You can work on

Or you can work om Magento\Sitemap\Model\ItemProvider\Composite argument list

See di.xml of vendor/magento/module-sitemap/etc/di.xml. On below code

<type name="Magento\Sitemap\Model\ItemProvider\Composite">
        <argument name="itemProviders" xsi:type="array">
            <item name="categoryProvider" xsi:type="object">Magento\Sitemap\Model\ItemProvider\Category</item>
            <item name="cmsPageProvider" xsi:type="object">Magento\Sitemap\Model\ItemProvider\CmsPage</item>
            <item name="productProvider" xsi:type="object">Magento\Sitemap\Model\ItemProvider\Product</item>

Suppose, I want to change at the Cms page list of sitemap. To build a module and that cmsPageProvider argument value.


<?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\Sitemap\Model\ItemProvider\Composite">
            <argument name="itemProviders" xsi:type="array">
                <item name="cmsPageProvider" xsi:type="object">MyVendor\MymoDule\Model\ItemProvider\MyCmsPage</item>


It means MyVendor\MymoDule\Model\ItemProvider\MyCmsPage Class will call On cms Page collection classes at sitemap generation instead of Magento\Sitemap\Model\ItemProvider\CmsPage

  • 1
    Note that for products specifically, there is a public method prepareSelectStatement on Magento\Sitemap\Model\ResourceModel\Catalog\Product that is specifically intended as a plugin extension point for modifying the query (so says the PHPDoc comment). Feb 26, 2021 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.