0

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

  • is it a page(cms)?i mean not product page. – Mujahidh Dec 23 '15 at 7:24
3

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
    }
}
0

First copy file from app\code\core\Mage\Sitemap\Model\Sitemap.php to app\code\local\Mage\Sitemap\Model\Sitemap.php and after add bellow code at line number : 201

$collection->addFieldToFilter('identifier',array('neq'=>'coupon-partners'));

OR

Find bellow code in generateXml() function

$changefreq = (string)Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
$priority   = (string)Mage::getStoreConfig('sitemap/page/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);

And replace this code:

$changefreq = (string)Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
$priority   = (string)Mage::getStoreConfig('sitemap/page/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
$collection->addFieldToFilter('identifier',array('neq'=>'coupon-partners'));

Tyr to generate sitemap again to admin side...

  • Copying files to app/code/local should be avoided whenever possible. It's better to create a rewrite. – Anna Völkl Dec 23 '15 at 7:41
  • This does not work because Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId) produces an array, not an object, addFieldToFilter only works on objects – eddhall Jul 19 '17 at 15:28

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.