Customize sitemap output for special requirements such as adding custom post types, excluding specific URLs, or modifying the ping behavior.
Adding Custom Post Types to the Sitemap
php
// Programmatically add a custom post type to the sitemap
$settings = get_option( 'seoforge_sitemap_settings', [] );
$enabled = $settings['enabled_types'] ?? [ 'post', 'page' ];
if ( ! in_array( 'portfolio', $enabled, true ) ) {
$enabled[] = 'portfolio';
$settings['enabled_types'] = $enabled;
update_option( 'seoforge_sitemap_settings', $settings );
// Flush cache so the new type appears immediately
SEOFORGE_Sitemap::instance()->invalidate_cache();
}Excluding Specific URLs from the Sitemap
Since SEO Forge uses the _seoforge_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, '_seoforge_noindex', '1' );
}
SEOFORGE_Sitemap::instance()->invalidate_cache();Disabling Google Ping on Publish
php
add_action( 'init', function () {
if ( ! class_exists( 'SEOFORGE_Sitemap' ) ) {
return;
}
remove_action( 'transition_post_status', [ SEOFORGE_Sitemap::instance(), 'maybe_ping_google' ] );
}, 20 );Increasing Max URLs Per Sitemap
php
$settings = get_option( 'seoforge_sitemap_settings', [] );
$settings['max_urls'] = 5000; // Increase from default 1000
update_option( 'seoforge_sitemap_settings', $settings );
SEOFORGE_Sitemap::instance()->invalidate_cache();—