首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Yoast自定义网站地图在Yoast 5.0中不起作用

Yoast自定义网站地图在Yoast 5.0中不起作用
EN

Stack Overflow用户
提问于 2017-07-15 05:17:40
回答 1查看 372关注 0票数 3

对于我的生活,我不明白为什么wordpress不运行这个过滤器。我将它添加到我的活动子主题的functions.php中,在functions.php中没有其他代码

代码语言:javascript
复制
/* 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

EN

回答 1

Stack Overflow用户

发布于 2017-07-15 07:57:54

相反,可以使用这个插件:https://wordpress.org/plugins/add-actions-and-filters/

如下图所示,在插件的主体中添加如下代码:

代码语言:javascript
复制
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;
}

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45111732

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档