簡體   English   中英

從 Yoast 站點地圖中排除多種帖子類型

[英]Exclude multiple post types from Yoast sitemap

Yoast 提供了一種解決方案,可以從它生成的 xml 站點地圖中排除 1 種帖子類型,但它沒有明確 state 如何排除多種帖子類型。這是他們建議您排除 1 種帖子類型的方式:

/**
 * Exclude a post type from XML sitemaps.
 *
 * @param boolean $excluded  Whether the post type is excluded by default.
 * @param string  $post_type The post type to exclude.
 *
 * @return bool Whether or not a given post type should be excluded.
 */
function sitemap_exclude_post_type( $excluded, $post_type ) {
    return $post_type === 'recipes';
}

add_filter( 'wpseo_sitemap_exclude_post_type', 'sitemap_exclude_post_type', 10, 2 );

此處查看原始文檔

解決方案是像這樣更改上面的代碼,列出您想在數組聲明中排除的帖子類型:

function my_sitemap_exclude_post_type( $excluded, $post_type ) {
    $excludedPostTypes = array('portfolio', 'testimonial', 'area-item', 'cool_timeline', 'author');
    if (in_array($post_type, $excludedPostTypes)) 
        return true;
        return false;
    }
add_filter( 'wpseo_sitemap_exclude_post_type', 'my_sitemap_exclude_post_type', 10, 2 );

在這種情況下,排除的項目是:'portfolio'、'testimonial'、'area-item'、'cool_timeline'、'author'

此解決方案由 Yoast 支持人員提供

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM