I want to create sitemap pro-grammatically using script,

any one have idea, to create sitemap using API or another way...


You can write your custom code as given below to generate sitemap.


namespace Vendor\Module\Model;

class TestGenerateSitemap {
    public function __construct(
        \Magento\Sitemap\Model\Sitemap $sitemap
    ) {
        $this->sitemap = $sitemap;

    public function createSitemapXml() {

and call Vendor\Module\Model\TestGenerateSitemap::createSitemapXml() from anywhere to generate the sitemap.

You can also create an api or console command and utilize \Magento\Sitemap\Model\Sitemap::generateXml() function to create the sitemap.

| improve this answer | |

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.