How to generate a sitemap.xml with image in Magento

This is good for SEO if product images include in the sitemap.xml file. We have implemented to add images URL in Magento sitemap.xml file.

file path : app/code/core/Mage/Sitemap/Model/Sitemap.php

Replace this code with existing code.

/**
* Generate products sitemap
*/
$changefreq = (string)Mage::getStoreConfig('sitemap/product/changefreq', $storeId);
$priority = (string)Mage::getStoreConfig('sitemap/product/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
$products = new Varien_Object();
$products->setItems($collection);
Mage::dispatchEvent('sitemap_products_generating_before', array(
'collection' => $products
));
foreach ($products->getItems() as $item) {
$image = Mage::getModel('catalog/product')->load($item->getId())->image;
$img = Mage::getModel('catalog/product')->load($item->getId())->getImageUrl();
$xml = sprintf(
'<url><loc>%s</loc><image:image><image:loc>%s</image:loc></image:image><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
htmlspecialchars($baseUrl . $item->getUrl()),
htmlspecialchars($baseUrl."media/catalog/product" . $image),
$date,
$changefreq,
$priority
);
$io->streamWrite($xml);
}
unset($collection);

Aly Chiman

Aly Chiman is a Blogger & Reporter at AlyChiTech.com which covers a wide variety of topics from local news from digital world fashion and beauty . AlyChiTech covers the top notch content from the around the world covering a wide variety of topics. Aly is currently studying BS Mass Communication at University.