Recent Blogs

  • Why A Travel Company Needs An Attractive Website?

    A website considered a great source of a marketing platform for a travel company. It is a place where you can share your availability and regularity all the time without unusual hindrances. A website should be responsive, user-friendly, and easy to operate. A travel company promotes itself through the best website to put trustworthy content. It may promote visitors and it would be a great platform to place tour packages.

    Why travel agencies needs a attractive website


sitemap in magento 2

In this tutorial you will learn how to configure sitemap in Magento 2 programmatically

what is a sitemap

A sitemap is a plain-text XML file that holds the link to all of the pages on your Magento store.
Once you add the links to the sitemap search engines can crawl your whole websites easily.
Therefore, it is important to keep the sitemap page updated as regularly as the content on your store changes.
Generating a Magento Sitemap also enhances the SEO of your online store.

Lets start how to configure sitemap in Magento 2 programmatically

In order to add custom URL to the Magento sitemap programmatically, you need to create a plugin for class Magento\Sitemap\Model\Sitemap.
Create an after plugin for collectSitemapItems() and add your custom URL to the collection.


Step 1 : Create di.xml in folder app/code/Egits/General/etc

            <?xml version="1.0"?>
    <config xmlns:xsi=""
        <type name="Magento\Sitemap\Model\Sitemap">
            <plugin name="add_new_url" sortOrder="1" disabled="false" type="Egits\General\Plugin\Model\SitemapPlugin"/>

Here I used Egits as vendor_name and General as my module_name.
Step 2: Create a plugin class SitemapPlugin in folder app/code/Egits/General/Plugin/Model

helper = $helper;

     * @param \Magento\Sitemap\Model\Sitemap $subject
    public function afterCollectSitemapItems(\Magento\Sitemap\Model\Sitemap $subject)
        $newItem = [];
        $storeId = $subject->getStoreId();
        $object = new \Magento\Framework\DataObject();
        $object->setUpdatedAt(date('Y-m-d h:i:s'));
        $newItem['unique_id'] = $object;
        $subject->addSitemapItem(new  \Magento\Framework\DataObject(
                'changefreq' => $this->helper->getPageChangefreq($storeId),
                'priority' => $this->helper->getPagePriority($storeId),
                'collection' => $newItem,

Then go to admin panel of your store and navigate to Marketing and click Sitemap under SEO & Search.

sitemap in magento 2

Under the Sitemap generator page, click on the Add Sitemap button on the right top corner if the sitemap is not yet added.
Fill the required fields such as File name and File Path.

sitemap in magento 2

Once it is done click the Generate link in the action column to generate the Magento sitemap.
Click on the Magento sitemap link to see the sitemap.
If the Magento sitemap page is already added then click the Generate button in the action column to complete the final step.
If you have followed the about instructions carefully then you have successfully added the URL to the sitemap in Magento 2.
Note: Hit the Magento 2 sitemap URL and ensure that your custom URL is added. As a Magento development company, we recommend you to keep your sitemap updated to improve your website ranking.
Well above you have read the process for sitemaping in Magento 2, then for making this process easiler please refer to the tutorial below.

Leave a Reply

Your email address will not be published. Required fields are marked *