List Extra Sitemap Files in Rank Math's Index
Lists extra sitemap files from other parts of your site in Rank Math's sitemap_index.xml.
Opens WPIDE on
Code
// Full URLs of extra sitemaps.
$wpide_rm_extra_sitemaps = array(
home_url( '/shop-sitemap.xml' ),
);
add_filter( 'rank_math/sitemap/index', function ( $xml ) use ( $wpide_rm_extra_sitemaps ) {
foreach ( $wpide_rm_extra_sitemaps as $url ) {
$xml .= "\t<sitemap>\n\t\t<loc>" . esc_url( $url ) . "</loc>\n\t\t<lastmod>" . esc_html( gmdate( 'c' ) ) . "</lastmod>\n\t</sitemap>\n";
}
return $xml;
}, 11 );
Notes
Use full URLs on the same domain.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.