Support Log in

17. Extending the Sitemap

Developer Guide
Prefer video? Watch the Rank Forge tutorials 9 short guides covering every feature Watch

Customize sitemap output for special requirements such as adding custom post types, excluding specific URLs, or changing the sitemap stylesheet.

Adding Custom Post Types to the Sitemap

Every public post type except attachments is listed in the sitemap index once it has a published post, so a public custom post type needs no setup. A post type is left out when “Show in search results” is switched off for it in the Title Templates card of the Settings screen. That switch is stored as a noindex flag in the rankforge_posttype_robots option, so it also sets the post type to noindex. The enabled_types key of rankforge_sitemap_settings is ignored. To list a post type that was switched off, remove its entry from the option:

php
// Remove the noindex flag of a custom post type: it is listed in the sitemap again
$robots = get_option( 'rankforge_posttype_robots', [] );

if ( isset( $robots['portfolio'] ) ) {
    unset( $robots['portfolio'] );
    update_option( 'rankforge_posttype_robots', $robots );

    // Flush cache so the type appears immediately
    RANKFORGE_Sitemap::instance()->invalidate_cache();
}

Excluding Specific URLs from the Sitemap

Since Rank Forge uses the _rankforge_noindex meta to control sitemap inclusion, you can programmatically exclude posts:

php
// Exclude all posts in a specific category from the sitemap
$posts = get_posts( [
    'category_name'  => 'internal-only',
    'posts_per_page' => -1,
    'fields'         => 'ids',
] );

foreach ( $posts as $pid ) {
    update_post_meta( $pid, '_rankforge_noindex', '1' );
}

RANKFORGE_Sitemap::instance()->invalidate_cache();

Changing the Sitemap Stylesheet

The sitemap index and the post type sitemaps point to an XSL stylesheet that makes them readable in a browser. Its address goes through the rankforge_sitemap_stylesheet_url filter. The sitemaps are cached for an hour, so call RANKFORGE_Sitemap::instance()->invalidate_cache() once after you add the filter.

php
add_filter( 'rankforge_sitemap_stylesheet_url', function ( $url ) {
    return get_stylesheet_directory_uri() . '/sitemap.xsl';
} );

Increasing Max URLs Per Sitemap

php
$settings = get_option( 'rankforge_sitemap_settings', [] );
$settings['max_urls'] = 5000; // Increase from default 1000
update_option( 'rankforge_sitemap_settings', $settings );
RANKFORGE_Sitemap::instance()->invalidate_cache();

—

Forge AI Assistant Online

Hi! I'm the Rank Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs