Adding a sitemap to your robots.txt is a good step to increasing the crawl rate of your site if your site is still young, even with older sites this is still a good step to take. In this guide, we will show you how to add the sitemap from Yoast SEO to the dynamic sitemap of all sites on your WordPress Multisite. This works with standard multisite installations and setups using domain mapping.

You can also follow this guide to add global rules to all your networks robots.txt files, you could expand on this as much as you want and even add rules to specific sites using a conditional statement with the current blog ID $site_id = get_current_blog_id();.

In this guide, we will just show you how to add a sitemap link to all sites robots.txt file. You will need to create a Must-Use Plugin (MU-Plugin) for your network, you could also use the Code Snippets plugin but I suggest an MU-Plugin.

The Function to Add Yoast SEO Sitemap Link to your dynamic Robots.txt file

/**
 * Add Yoast SEO sitemap to virtual robots.txt file network wide
 * https://wphelper.site/robots-txt-yoast-sitemap-multisite/
 */
function wphelper_network_robotstxt_function( $output, $public ) {
	$homeURL = get_home_url();

	$output .= "Sitemap: $homeURL/sitemap_index.xml\n";
	
	return $output;
}
add_filter( 'robots_txt', 'wphelper_network_robotstxt_function', 20, 2 );

Simply copy and paste the function above to your MU-Plugin, this will automattically add the sitemap link to all dynamic robots.txt files on your MU network even if you have domain mapping active.

I hope you found this article useful, please leave a comment below if you have any suggestions or if you got stuck with any step. WP Helper provides premium WordPress support & maintenance plans and also one-off WordPress jobs and support.