Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon how do I alter the number of sitemap entries in Yoast SEO


how do I alter the number of sitemap entries in Yoast SEO


To alter the number of sitemap entries in Yoast SEO, you can use the `wpseo_sitemap_entries_per_page` filter. Here is an example of how to do it:

php
function max_entries_per_sitemap() {
    return 100;
}

add_filter( 'wpseo_sitemap_entries_per_page', 'max_entries_per_sitemap' );

This code sets the maximum number of entries per sitemap to 100. You can adjust this value to suit your specific needs.

Additionally, you can use the `wpseo_sitemap_entries_per_page` filter to limit the number of sitemap entries based on specific conditions. For example, you can limit the number of entries per sitemap based on the post type or category:

php
function max_entries_per_sitemap() {
    if ( get_post_type() === 'post' ) {
        return 50;
    } else {
        return 100;
    }
}

add_filter( 'wpseo_sitemap_entries_per_page', 'max_entries_per_sitemap' );

This code sets the maximum number of entries per sitemap to 50 for posts and 100 for other post types.

You can also use the `wpseo_sitemap_entries_per_page` filter to limit the number of entries per sitemap based on the category:

php
function max_entries_per_sitemap() {
    $category = get_the_category();
    if ( $category ) {
        if ( $category->slug === 'category-slug' ) {
            return 20;
        } else {
            return 50;
        }
    }
}

add_filter( 'wpseo_sitemap_entries_per_page', 'max_entries_per_sitemap' );

This code sets the maximum number of entries per sitemap to 20 for posts in the category "category-slug" and 50 for posts in other categories.

These are just a few examples of how you can use the `wpseo_sitemap_entries_per_page` filter to alter the number of sitemap entries in Yoast SEO.

Citations:
[1] https://webseo.co.za/limit-number-sitemap-entries-yoast-seo-plugin
[2] https://yoast.com/yoast-seo-snippets-to-customize-your-site/
[3] https://yoast.com/help/xml-sitemaps-in-the-wordpress-seo-plugin/
[4] https://developer.yoast.com/features/xml-sitemaps/api/
[5] https://github.com/Yoast/wordpress-seo/issues/12161