Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi, do you wish to exclude certain category archive pages from the categories sitemap or exclude all posts that belong to a certain category from the posts sitemap?

    Thread Starter roxer82

    (@roxer82)

    Hi. I need to exclude all posts (1417 posts) that belong to certain category from posts sitemap.
    I didn’t think about the category archive pages, but it would be great if I also could exclude it from the categories sitemap.
    I mean, I wish to exclude from my sitemap.xml everything about certain category.

    Hi, this is not possible with the free version but is planned for the upcoming Pro version.

    However, you could use the below code snippet to achieve at least the Posts exclusion part. The code snippets can be added either to your custom/child theme’s functions.php or using a “Code Snippets” plugin (there are several plugins available on wp.org) …

    // Exclude posts that belong to category by ID.
    function my_custom_exclusion( $exclude, $post_id ) {
        // Change this to match your category ID number.
        $cat_id = 123;
    
        if ( in_array( $cat_id, (array) wp_get_post_categories( $post_id ) ) {
            return true;
        }
     
        // Return original status.
        return $exclude;
    }
    add_filter( 'xmlsf_excluded', 'my_custom_exclusion', 10, 2 );

    Excluding a particular taxonomy term is not possible yet. Your only option is to disable the complete Category taxonomy or all taxonomy sitemaps.

    Thread Starter roxer82

    (@roxer82)

    Thank you! It worked!

    I just had to add a ) at the end of the condition.

    My apologies for the missing ), I must admit I did not verify my sloppy code… Good to hear you fixed it ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Exclude categories’ is closed to new replies.