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.
What is Yoast SEO
Yoast SEO is a WordPress plugin that helps your site perform better in search engines like Google. It also gives you the tools to bring your content to the highest standards of SEO and overall readability. Here, we’ll explain how our plugin helps you build the best website you possibly can!
Yoast SEO offers you loads of tools and features to boost your SEO. Some of these features influence the SEO of your whole site; other features help you to optimize individual posts and pages for search engines. At Yoast, we really believe in our motto “SEO for everyone”, so you can access all the most essential SEO tools in our free Yoast SEO plugin. But if you really want to give your SEO a boost, upgrade to Yoast SEO Premium — it’s got even more amazing SEO features!
If you want your posts and pages to appear in the search results, you need to optimize them! So, when you use WordPress to create/edit posts, you’ll find a whole load of Yoast SEO tools to help you draft and optimize great content. And if you think SEO optimization is all about keywords, think again. The tools and tips in our Yoast SEO plugins put equal focus on quality content and user experience, too. Trust us — it will all help your rankings, whether directly or indirectly.
The Function to Add Yoast SEO Sitemap Link to your dynamic Robots.txt file
You can also follow this guide to add global rules to all your network 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 site’s robots.txt files. 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.
/** * Add Yoast SEO sitemap to virtual robots.txt file network wide * https://wphelper.io/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 automatically 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.
For more information on automatically adding Yoast Sitemap to Dynamic Robots.txt, let us help you accordingly, from start to finish, with one-Time fixes, custom plans, or monthly routines for your WordPress website.