Yoast Custom Sitemap not working in Yoast 5.0

In real life, I can't figure out why Wordpress won't run this filter. I added it to my Active Child theme 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 here: https://kb.yoast.com/kb/add-external-sitemap-to-index/

he does not work. I am using Yoast 5.0 and Wordpress 4.8

+3


source to share


1 answer


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

Add your code just like this to the plugin body, as described in the image below:

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 introduces filters in a different way, which we usually do manually. Therefore, it must work around any incompatibility that prevents the filter from performing.

+1


source







All Articles