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?
Exclude Specific Products, Categories, and CMS Pages from Sitemap.xml in Magento 2
categorycms-pagesmagento2productsitemaps
Best Answer
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
Magento\Sitemap\Model\ResourceModel\Catalog\Category:getCollection()
Magento\Sitemap\Model\ResourceModel\Catalog\Product:getCollection()
Magento\Sitemap\Model\ResourceModel\Cms\Page:getCollection()
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 listSee
di.xml
ofvendor/magento/module-sitemap/etc/di.xml
. On below codeSuppose, I want to change at the Cms page list of sitemap. To build a module and that
cmsPageProvider
argument value.Example:
It means
MyVendor\MymoDule\Model\ItemProvider\MyCmsPage
Class will call On cms Page collection classes at sitemap generation instead ofMagento\Sitemap\Model\ItemProvider\CmsPage