3

对于我的生活,我无法弄清楚为什么 wordpress 不会运行这个过滤器。我将它添加到我的 Active Child 主题的 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

4

1 回答 1

1

相反,使用这个插件: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;
}

在此处输入图像描述

这个插件以我们通常手动执行的不同方式注入过滤器。因此,它应该绕过阻止执行过滤器的任何不兼容性。

于 2017-07-14T23:57:53.753 回答