Yoast自定义站点地图不工作Yoast 5.0
问题描述:
对于我的生活,我不明白为什么WordPress不会运行此过滤器。我把它添加到我的Active子主题的functions.php中,存在的functions.phpYoast自定义站点地图不工作Yoast 5.0
/* 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;
}
NO其他代码这是从这里被复制:https://kb.yoast.com/kb/add-external-sitemap-to-index/
这是行不通的。我使用Yoast 5.0和WordPress 4.8
答
相反,使用这个插件: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;
}
该插件以我们通常手动执行的不同方式注入过滤器。因此它应该绕过阻止过滤器执行的任何不兼容性。
你没有回答这个问题。 – Mauro
我在localhost中测试过它,它为我工作,所以我不知道为什么你会投我的答案。 –
,因为这个问题涉及Yoast SEO中的自定义站点地图和本文https://kb.yoast.com/kb/add-external-sitemap-to-index/如果您建议的插件有效,您应该解释为什么是示例在文章不起作用。请编辑答案,我会将它投票 – Mauro