• I have 2 sitemaps that are not generated by wordpress, but are part of my main website. I know i could add them to webmaster tools separately, but id like to keep all of my sitemaps in the index as it makes most sense to do this.

    Ive tried the following code and it doesnt seem to add anything to the sitemap.

    add_action(‘init’, ‘enable_custom_sitemap’);
    function enable_custom_sitemap(){
    global $wpseo_sitemaps;
    $wpseo_sitemaps->register_sitemap(‘xml’, ‘sitemaps/text.xml’);
    }

    https://www.ads-software.com/plugins/wordpress-seo/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Had a similar problem, solved it like this, sets the correct last changed date as well, maybe it helps.

    // Yoast SEO, add own sub-sitemap
    // works only after SEO -> XML Sitemaps -> Post Types (change something and back, some cache?)
    function my_wpseo_sitemap_index() {
    	$url = get_bloginfo( 'url' ) . '/other-sitemap.xml';
    
    	// https://wordpress.stackexchange.com/a/188461
    	require_once( ABSPATH . 'wp-admin/includes/file.php' );
    	$path = get_home_path() . 'other-sitemap.xml';
    
    	// https://wordpress.stackexchange.com/a/8404
    	date_default_timezone_set( get_option('timezone_string') );
    	$lastmod = date( 'c', filemtime( $path ) );
    
    	$xml = '<sitemap>' . "\n";
    	$xml .= '<loc>' . $url . '</loc>' . "\n";
    	$xml .= '<lastmod>' .  $lastmod . '</lastmod>' . "\n";
    	$xml .= '</sitemap>' . "\n";
    	return $xml;
    }
    add_filter( 'wpseo_sitemap_index', 'my_wpseo_sitemap_index' );

    Remember to add/remove a checkbox in “Post Types” and save changes in Yoast SEO, otherwise the added sitemap might not appear in sitemap_index.xml

    Thread Starter nerdburglars

    (@nerdburglars)

    Ah yes this did the trick. Thank you. So my guess is that the wpseo_sitemap_index filter is only called when you toggle a page typpe checkbox and doesnt get triggered during regular page use

    If the filter only gets called after a toggle of checkbox, it would be a bug in Yoast SEO.

    I had the impression that there is some cache expire time involved and the toggle clears the cache, but I am not sure.

    Let me know if you find out ??

    @nerdburlars and @ov3rfly

    Thanks for posting and answering this question. Seriously I was stumped with this exact same problem today and after some web searching I found the answer.

    Seriously y’all rock!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding Custom Sitemap To Sitemap Index’ is closed to new replies.