Exclude Taxonomy

#59738
  • Resolved Bryan Rainey
    Rank Math free

    I’m trying to exclude my cateogry “Courses” from the sitexml. Should I use the code below for this? And if so, can you please provide a quick example of what that code would look like?

    /**
    * Filter decision if taxonomy is excluded from the XML sitemap.
    *
    * @param bool $exclude Default false.
    * @param string $type Taxonomy name.
    */
    add_filter( ‘rank_math/sitemap/exclude_taxonomy’, function( $exclude, $type ){
    return $exclude;
    }, 10, 2 );

    Thanks!
    Bryan

Viewing 12 replies - 1 through 12 (of 12 total)
  • …sorry, to be clear, I’m trying to remove ALL posts associated with the Category “Courses”.

    Tried adding the below to functions.php, but it did not work.

    add_filter( ‘rank_math/sitemap/posts_to_exclude’, function( $posts_to_exclude ){
    $posts_ids = [ 333, 999, 111 ]; // Add the post ids you want to exclude seperated by comma.
    return array_merge( $posts_to_exclude, $posts_ids );
    });

    Hello,

    Thank you for contacting Rank Math today.

    You can try and customize the following function.

    /**
     * Filter decision if post type is excluded from the XML sitemap.
     *
     * @param bool   $exclude Default false.
     * @param string $type    Post type name.
     */
    add_filter( 'rank_math/sitemap/exclude_post_type', function( $exclude, $type ){
    	return $exclude;
    }, 10, 2 );
    

    Looking forward to helping you. Thank you.

    ​​​​​​

    I appreciate the response, but could you give me a quick example on what that code would look like if I was to exclude a post with the ID 101?

    I don’t need to exclude by post type. I want to exclude certain posts added to a certain category. I can take care of finding the posts assigned to a particular category.

    What I can’t seem to do is get the Rank Math filter to actually work at removing the posts from the sitemap.

    Hello,

    Thank you for contacting Rank Math today.

    To exclude specific posts you can use the following option in Rank math > sitemap > general
    img

    Hope this helps you. Thank you.

    ​​​​​​

    Yeah I saw that, but I’ve got over 30+ posts to exclude all in a “Courses” category and I was hoping to do that via code and your filter so I didn’t have to remember to add it to Rank Math every time.

    Thoughts?

    Hello,

    Thank you for contacting Rank Math today.

    Allow me to consult if it’s possible to exclude specific posts using their post id.
    However, if the posts to be excluded are in the same category, you may choose the option to exclude terms shown in my previous post screenshot.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Thanks. I tried that. I exlcuded the cateogry (per your screenshot), but it only excluded the category from the category-sitemap.xml. It did not exclude any posts assigned to that category in the post-sitemap.xml.

    All posts assigned to the “Courses” cateogry still show in the post-sitemap.xml even though I’ve added the category ID to the “Exclude Terms”.

    Thanks for the continued support and conversation. I love Rank Math and trying to find a way to make this work.

    Todd
    Rank Math free

    Hello,

    Settings something as noindex is the quickest way of excluding it from the sitemap. You do not need to fiddle with the code or add the post IDs.

    Alternatively, you can use the code my colleague provided like this:

    add_filter( 'rank_math/sitemap/exclude_post_type', function( $exclude, $type ){
        if ( $type === 'enter-post-type' ) {
             return false;
        }
        return $exclude;
    });

    Make sure to change enter-post-type with the actual name of the post type.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thank you, Todd! Yes, that’ll work.

    One last question. The post-type is just Post. These are not setup as a custom post type. Which filter would I use if I wanted to programatically exclude all posts assigned to a particular category?

    Thanks.

    Hello,

    Thank you for the follow up.

    I modified the shared code a bit. Could you please test it and let us know.

    add_filter( 'rank_math/sitemap/exclude_post_type', function( $exclude, $type ){
        if ($type === 'enter-post-type' && is_category('enter-category')) {
             return false;
        }
        return $exclude;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 12 replies - 1 through 12 (of 12 total)

The ticket ‘Exclude Taxonomy’ is closed to new replies.