Yoast SEO: add external sitemap to index

The Yoast plugin creates sitemaps on the fly for the content within WordPress. The plugin creates a sitemap on the fly. This means a sitemap is updated automatically when you add, edit, or delete content. In some cases, the cache functionality on your site prevents this from happening. Cache can be handled through a lot of methods so you may not have intentionally added a cache feature but it’s there nonetheless.

In some cases, you may have sitemaps for other parts of your site that you want to add to our sitemap index. For this purpose, they introduced the ‘wpseo_sitemap_index’ filter.

// Add the following to themes/functions.php
function add_sitemap_custom_items(){
	$sitemap_custom_items = '<sitemap>
		<loc>http://www.website.com/custom-page-1/</loc>
		<lastmod>2012-12-18T23:12:27+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>http://www.website.com/custom-page-2/</loc>
		<lastmod>2012-12-18T23:12:27+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>http://www.website.com/custom-page-3/</loc>
		<lastmod>2012-12-18T23:12:27+00:00</lastmod>
	</sitemap>';
 
	return $sitemap_custom_items;
}
add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );
 
// You may also need to prevent caching for a while in order to make the change appear
// Disable the transient caching by adding this line of code to your theme's functions.php file
add_filter('wpseo_enable_xml_sitemap_transient_caching', '__return_false');