3

For the life of me, I cannot figure out why wordpress won't run this filter. I added it to my Active Child theme's functions.php, there is NO other code in functions.php

/* Add External Sitemap to Yoast Sitemap Index
 * Credit: Paul https://wordpress.org/support/users/paulmighty/
 * Last Tested: Oct 07 2016 using Yoast SEO 3.6 on WordPress 4.6.1
 */
add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );
function add_sitemap_custom_items(){
$sitemap_custom_items = '<sitemap>
<loc>http://www.website.com/external-sitemap.xml</loc>
<lastmod>2017-05-22T23:12:27+00:00</lastmod>
</sitemap>
<sitemap>
<loc>http://www.website.com/external-sitemap-2.xml</loc>
<lastmod>2017-05-22T23:12:27+00:00</lastmod>
</sitemap>
<sitemap>
<loc>http://www.website.com/external-sitemap-3.xml</loc>
<lastmod>2017-05-22T23:12:27+00:00</lastmod>
</sitemap>';
return $sitemap_custom_items;
}

This was copied from here: https://kb.yoast.com/kb/add-external-sitemap-to-index/

it does not work. I'm using Yoast 5.0 and Wordpress 4.8

1 Answer 1

1

Instead, Use this plugin: https://wordpress.org/plugins/add-actions-and-filters/

Add your code just like this within the body of the plugin as explained in the image bellow:

add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );
function add_sitemap_custom_items(){
$sitemap_custom_items = '<sitemap>
<loc>http://www.website.com/external-sitemap.xml</loc>
<lastmod>2017-05-22T23:12:27+00:00</lastmod>
</sitemap>
<sitemap>
<loc>http://www.website.com/external-sitemap-2.xml</loc>
<lastmod>2017-05-22T23:12:27+00:00</lastmod>
</sitemap>
<sitemap>
<loc>http://www.website.com/external-sitemap-3.xml</loc>
<lastmod>2017-05-22T23:12:27+00:00</lastmod>
</sitemap>';
return $sitemap_custom_items;
}

enter image description here

This plugin injects filters in a different way that we usually do manually. Hence It should bypass any incompatibility that is deterring the filter from being executed.

4
  • You are not answering the question.
    – Mau
    Jul 21, 2017 at 3:21
  • I tested it in localhost and it worked for me so I am not sure why you would vote down my answer. Jul 21, 2017 at 15:46
  • because the question refers to Custom Sitemaps in Yoast SEO and this article kb.yoast.com/kb/add-external-sitemap-to-index if the plugin you suggested works, you should explain why is the example in the article not working. please edit the answer and i will vote it up
    – Mau
    Jul 26, 2017 at 2:44
  • 1
    @Mauro Yes, throughout this plugin you can force custom filters of your own, and in this example, I added a filter that adds custom sitemaps within Yoast sitemap file "sitemap_index.xml" Jul 26, 2017 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.