• Resolved ahhhaweb

    (@ahhhaweb)


    I have an ecommerce site that generates dynamic product pages of a couple of different types. The dynamic pages can be identified as https://www.mysite.com/dynamic-category1/ and https://www.mysite.com/dynamic-category2/ These pages are constructed on the fly at run time from links on landing pages. I’d like to get these pages into a site map. I can crawl the site with a tool like Screaming Frog and it will pick the links for the regular landing pages and generate a site map with the dynamic pages and Googlebot is already finding and indexing the pages but I’d like to have them included in some category sitemaps and I’m hoping there’s a way to get Rank Math sitemap functions to accomplish this so I can automate the process.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Rank Math

    (@rankmath)

    Hello @ahhhaweb

    Thank you for contacting the support.

    You can use the following filter to add links to the required sitemap type:

    /**
     * Filter to add extra URLs to the XML sitemap by type.
     *
     * Only runs for the first page, not on all.
     *
     * @param string $content String content to add, defaults to empty.
     */
    if ( 1 === $current_page ) {
        $xml .= $this->do_filter( "sitemap/{$type}_content", '' );
    }

    If you want to add it to the category taxonomy sitemap you need to do try the following filter:

    add_action( 'rank_math/sitemap/category_content', 'rank_math_add_custom_dynamic_url' );
    function rank_math_add_custom_dynamic_url() {
        $urls = '';
    
        $urls .= '<url>
            <loc>https://www.mysite.com/dynamic-category1/</loc>
            <lastmod>2019-02-22T18:02:24+00:00</lastmod>
        </url>';
    
        $urls .= '<url>
            <loc>https://www.mysite.com/dynamic-category2/</loc>
            <lastmod>2019-02-22T18:02:24+00:00</lastmod>
        </url>';
    
        return $urls;
    }

    Please let us know if that helps. Thank you.

    Thread Starter ahhhaweb

    (@ahhhaweb)

    Thanks for the great support! Providing actual code is phenomenal! I tried adding it to the class-sitemap.php file but that had no effect. A new site map just generated and it looks pretty much the same.

    To be clear, what I need is for the site map generator to crawl and follow my href anchor links. The way my site works is a normal WordPress page template will call an API that returns a product list with hrefs that will generate product listing pages that will contain hrefs that generate product detail pages which contain prices and add-to-cart buttons. I need those product detail pages with the prices added into the sitemap so I can encourage Google to index them and pick up the structured data product tags I implemented.

    Thanks!!

    Plugin Author Rank Math

    (@rankmath)

    Hello @ahhhaweb

    Can you please turn off the Sitemap’s caching and then test?
    https://rankmath.com/kb/filters-hooks-api-developer/#enable-disable-sitemap-cache

    Please do flush the permalinks cache by simply saving the settings of the Sitemaps and the Permalinks.

    Let us know if that helped. Thank you.

    Plugin Author Rank Math

    (@rankmath)

    Hello @ahhhaweb

    Assuming you got it sorted, we are closing this topic.

    If you need any further assistance, please feel free to open a new support topic and we will be more than happy to assist.

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sitemap Dynamic Pages’ is closed to new replies.