Question

Hello Guys, how to remove some cms pages from sitemap.xml

No correct solution

OTHER TIPS

If you don't actually need them at all, you can disable them.

I found solution for it.hope this help someone its based on magento 2.2 need to override sitemap model file.so first of all create di.xml file at your module directory

/app/code/Vendor/Module/etc/di.xml

add below code in 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">
  <preference for="Magento\Sitemap\Model\Sitemap" type="Vendor\Module\Model\Sitemap"/>
</config>

create "Sitemap.php" in "Vendor\Module\Model" and add below code

public function collectSitemapItems()
    {
        $helper = $this->_sitemapData;
        $storeId = $this->getStoreId();
        $this->_storeManager->setCurrentStore($storeId);

        $this->addSitemapItem(new DataObject(
            [
                'changefreq' => $helper->getCategoryChangefreq($storeId),
                'priority' => $helper->getCategoryPriority($storeId),
                'collection' => $this->_categoryFactory->create()->getCollection($storeId),
            ]
        ));

        $this->addSitemapItem(new DataObject(
            [
                'changefreq' => $helper->getProductChangefreq($storeId),
                'priority' => $helper->getProductPriority($storeId),
                'collection' => $this->_productFactory->create()->getCollection($storeId),
            ]
        ));

        $this->addSitemapItem(new DataObject(
            [
                'changefreq' => $helper->getPageChangefreq($storeId),
                'priority' => $helper->getPagePriority($storeId),
                'collection' => $this->_getPageCollection($storeId),
            ]
        ));
    }

public function _getPageCollection($storeId)
    {
        $collection = [];
        foreach ($this->_cmsFactory->create()->getCollection($storeId) as $item) {
            if (in_array($item->getUrl(),$this->getExcludedPages())
            ) {
                continue;
            }
            $collection[] = $item;
        }
        return $collection;
    }

    public function getExcludedPages()
    {
       return ['home', 'no-route',about-us,'privacy-policy'];
    }

Now please clear cache and regenerate "Sitemap.xml"

Cheers!!!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top