Magento – Want to remove a specific url from Magento sitemap.xml

magento-1.9sitemapsxml

Want to remove a specific url from default magento sitemap.xml

I don't want this url http://www.globekart.com/coupon-partners.html in the sitemap http://www.globekart.com/sitemap/sitemap.xml

Please help

Best Answer

Please do not just copy the complete file to app/code/local (as mentioned in the other answer here). This is not upgrade safe and will cause some extra work when upgrading.

It's better to create a seperate module for this, for example YourNamespache_Sitemap with a proper rewrite of the model Mage_Sitemap_Model_Sitemap there.

In your config.xml put the following:

<?xml version="1.0"?>
<config>
    <modules>
        <YourNamespache_Sitemap>
            <version>0.1.0</version>
        </YourNamespache_Sitemap>
    </modules>
    <global>
        <models>
            <yournamespace_sitemap>
                <class>YourNamespache_Sitemap_Model</class>
            </yournamespace_sitemap>
            <sitemap>
                <rewrite>
                    <sitemap>YourNamespache_Sitemap_Model_Sitemap</sitemap>
                </rewrite>
            </sitemap>
        </models>
    </global>
</config>

And in app/code/[local/community]/YourNamespace/Sitemap/Model create the class Sitemap.php which extends the original sitemap model class. You only need to copy and adjust the generateXml() method in there, the rest can stay in the parent class.

class YourNamespace_Sitemap_Model_Sitemap extends Mage_Sitemap_Model_Sitemap {

    /**
     * Generate XML file
     *
     * @return Mage_Sitemap_Model_Sitemap
     */
    public function generateXml()
    {
        //copied and adjusted code from the parent generateXml method
    }
}