Automatically Add Yoast Sitemap to Dynamic Robots.txt

Contents

Build your own WordPress Support Plan

Expert, yet affordable WordPress support & maintenance plans.
View our pricing

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.

image 28

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.

Written By
Adam Haworth
Founder of WP Helper.
You will also like these articles

Relax Knowing Your WordPress Site Is Secure & Running Smoothly 24/7

Let us manage your WordPress site, everything from security to updates will be taken care of. Support plans also come with dedicated support so we can do anything from adding content to customising your site for you.

Same Day Professional WordPress Support

Get WordPress Support Today

Need help with a single WordPress problem, today? We can help with anything from adding analytics tracking code to site hack recovery. Full money back guarantee on all jobs.

1. Submit a Support Request

Use our support ticket form below to send details of your problem to our developers.

2. Get a Quote

We will review your request and provide a quote within 24 hours (but usually within a few hours).

3. We fix your WordPress problem

Our team will begin fixing your WordPress problem the same day.

4. 100% Money Back Guarantee

If we can’t fix the problem for the amount quoted we will refund you 100%.

  • Do you have a screenshot of the issue or have a copy of the theme or plugin that is at fault? If you want to upload php, html or css please zip first.
    Drop files here or
    Accepted file types: jpg, jpeg, png, pdf, zip, gzip, rar, doc, txt, Max. file size: 15 MB, Max. files: 10.