2017-07-14 89 views
2

對於我的生活,我不明白爲什麼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

回答

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; 
} 

enter image description here

該插件以我們通常手動執行的不同方式注入過濾器。因此它應該繞過阻止過濾器執行的任何不兼容性。

+0

你沒有回答這個問題。 – Mauro

+0

我在localhost中測試過它,它爲我工作,所以我不知道爲什麼你會投我的答案。 –

+0

,因爲這個問題涉及Yoast SEO中的自定義站點地圖和本文https://kb.yoast.com/kb/add-external-sitemap-to-index/如果您建議的插件有效,您應該解釋爲什麼是示例在文章不起作用。請編輯答案,我會將它投票 – Mauro

相關問題