Add Extra Pages to Google Sitemap

sitemaps

We have a storelocator module on our Magento store, it works well but it is not being added to the Magento google sitemap.

Is there a way to add to our sitemap which Magento automatically generates?

Best Answer

You need to override the method Mage_Sitemap_Model_Sitemap::generateXml because Magento does not offer an event you can use for that.
Insert your code after the cms pages are added

This is the code that adds the cms pages to the sitemap:

    /**
     * Generate cms pages sitemap
     */
    $changefreq = (string)Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
    $priority   = (string)Mage::getStoreConfig('sitemap/page/priority', $storeId);
    $collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
    foreach ($collection as $item) {
        $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
            htmlspecialchars($baseUrl . $item->getUrl()),
            $date,
            $changefreq,
            $priority
        );
        $io->streamWrite($xml);
    }
    unset($collection);

You have to do a similar thing with your page.
You need to loop through your custom pages and do this:

 $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
            htmlspecialchars($baseUrl . $item->getUrl()), //url of your custom page
            $date,
            $changefreq, //should be a config value
            $priority //should be a config value
        );
        $io->streamWrite($xml); //write xml node to the big sitemap xml
Related Topic