对于我的生活,我不明白为什么wordpress不运行这个过滤器。我将它添加到我的活动子主题的functions.php中,在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;
}这是从这里复制的:https://kb.yoast.com/kb/add-external-sitemap-to-index/
它不起作用。我使用的是Yoast 5.0和Wordpress 4.8
发布于 2017-07-15 07:57:54
相反,可以使用这个插件:https://wordpress.org/plugins/add-actions-and-filters/
如下图所示,在插件的主体中添加如下代码:
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;
}

这个插件以一种不同的方式注入过滤器,这是我们通常手动做的。因此,它应该绕过任何阻碍过滤器执行的不兼容性。
https://stackoverflow.com/questions/45111732
复制相似问题