Last active
May 6, 2020 22:01
-
-
Save janzikmund/6bdd5f795e8599fe693a9291ddfd9201 to your computer and use it in GitHub Desktop.
WordPress add sitemap_index.xml link to robots.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Link sitemap in robots.txt | |
*/ | |
add_filter('robots_txt', function($robots) { | |
if(get_option( 'blog_public' )) { | |
// add sitemap link | |
$robots .= "\nSitemap: " . site_url() . "/sitemap_index.xml\n"; | |
} | |
return $robots; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment