Skip to content

Instantly share code, notes, and snippets.

@amboutwe
Last active November 2, 2021 13:17
Show Gist options
  • Save amboutwe/5392b77d67c9a4bc417fa62899422e4c to your computer and use it in GitHub Desktop.
Save amboutwe/5392b77d67c9a4bc417fa62899422e4c to your computer and use it in GitHub Desktop.
Add the Yoast SEO sitemap index to the WordPress generated robots.txt file.
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Add Sitemap Index To Generated Robots.txt
* Credit: Ben https://github.com/retlehs
* Last Tested: Mar 13 2017 using Yoast SEO 4.4 on WordPress 4.7.3
*/
add_action('do_robots', 'custom_robotstxt');
function custom_robotstxt() {
echo 'Sitemap: ' . get_home_url() . '/sitemap_index.xml';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment