Adding custom URLs to the sitemap does not respect “Links Per Sitemap”

#169658
  • Resolved David Ascienzo
    Rank Math free

    Hello, as the title suggests, I’m finding that adding custom URLs to the sitemap does not respect the “Links Per Sitemap” setting.

    I followed the guidance from here in order to create a filter that adds additional URLs to the sitemap from a custom database table.

    It works just fine after regenerating the sitemap, however, the primary issue is that all of the URLs are added to the sitemap without any pagination. So I have well over 200 items on a single sitemap. Is there a way to add these items while ensuring that the sitemap is broken up into separate pages so I can follow best practices? Thank you!

    Note: Here is an example of my filter.

    function rank_math_add_custom_urls(): string
    {
            $urls = '';
            $site_url = get_site_url();
            foreach(CustomMysql_Util::get_custom_sitemap_links() as $result) {
                $url = "$site_url" . "$result->uri";
                $lastmod = "$result->lastmod";
                $value = "<url>
                    <loc>$url</loc>
                    <lastmod>$lastmod</lastmod>
                </url>";
                $urls .= $value;
            }
            return $urls;
    }
    add_action( 'rank_math/sitemap/page_content', 'rank_math_add_custom_urls', 10 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • After a lot of debugging I was able to use this solution to fit my use case. Good luck to anyone who stumbles upon this post!

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for the delay and for any inconvenience this issue may have caused you.

    It seems that you have already found a fix for this issue and marked this ticket as already resolved. We also appreciate you sharing the solution for this concern.

    If you have any other concerns, please don’t hesitate to contact us anytime by creating a new ticket to assist you further with anything else.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

The ticket ‘Adding custom URLs to the sitemap does not respect “Links Per Sitemap”’ is closed to new replies.