-
如何從 Yoast sitemap_index.xml 移除特定文章類型索引
我使用 Yoast 的 API 建立自訂的 XML 網站地圖,將我所有的網站頁面和一些其他的文章類型整合為一。我對翻譯過的網頁也做了同樣的處理,讓它們有自己的網站地圖。
我想從 sitemap_index.xml 中移除 Yoast 建立的 XML 網站地圖,這樣就只有我自訂的網站地圖在其中了。我找不到如何實現這一目標的任何參考資料。我嘗試使用
wpseo_sitemap_exclude_post_type
過濾器來移除其他網站地圖的文章類型,但這樣做也會將我的自訂網站地圖從網站地圖索引中移除(因為它與我排除的文章類型相同)。有沒有辦法做到這一點?
馬丁-
您可以在 functions.php 檔案中使用以下程式碼:
function yoast_sitemap_exclude_post_type_sp( $value, $post_type ) {
// 移除 post_type : 產品、文章、頁面
if ( $post_type == 'product' || $post_type == 'post' || $post_type == 'page') {
返回 true;
}
}
add_filter( 'wpseo_sitemap_exclude_post_type', 'yoast_sitemap_exclude_post_type_sp', 10, 2 );
[在此輸入圖片說明][1]
-
@ava-martin 這如何解決問題?請解釋您為了解決這個問題做了哪些變更。
此外,我在描述中提到我已經嘗試使用 wpseo_sitemap_exclude_post_type 過濾器來排除「page」和「people」這兩種文章類型,但這樣做會導致我的自訂網站地圖也從索引中消失。😅
-
-