Add Your Own Sitemaps to the Yoast Sitemap Index
Lists extra sitemap files, such as one from a shop, forum or static section, in the Yoast SEO sitemap_index.xml so search engines find them in one place.
Opens WPIDE on
Code
// Full URLs of extra sitemap files.
$wpide_extra_sitemaps = array(
home_url( '/shop-sitemap.xml' ),
home_url( '/forum/sitemap.xml' ),
);
add_filter( 'wpseo_sitemap_index', function ( $xml ) use ( $wpide_extra_sitemaps ) {
$lastmod = gmdate( 'c' );
foreach ( $wpide_extra_sitemaps as $url ) {
$xml .= "<sitemap>\n\t<loc>" . esc_url( $url ) . "</loc>\n\t<lastmod>" . esc_html( $lastmod ) . "</lastmod>\n</sitemap>\n";
}
return $xml;
} );
Notes
Use full URLs on your own domain; search engines ignore cross-site sitemaps without verification.
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.