Hide posts from sitemap that belong to certain category?

#82040
  • Resolved D E
    Rank Math free

    Hello,

    I’m trying to hide all posts from the sitemap that belong to a specific category.
    How can I accomplish this via a function instead of having to enter every Post ID in the admin area?

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math today.

    You can add a noindex tag to the page by editing the individual pages and checking the noindex checkbox in Rank math meta box under Advanced tab.
    img
    This will automatically remove the pages from the sitemap.

    Looking forward to helping you. Thank you.

    ​​​​​​​

    D E
    Rank Math free

    Hello, this is for any posts that fall in a certain category. Is there a way to do this via the hook method instead of us having to edit every single post to accomplish this? Thanks!

    Alberto
    Rank Math business

    Hello,

    You could add the following code replacing your-category-slug with the slug of the category you want all its posts as no-index.

    /**
     * Allows filtering of the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
         global $post;
         // filter for only a specific post type
         if(in_category('your-category-slug')){
            $robots['index'] = "noindex";
            $robots['follow'] = "nofollow";
            return $robots;
         }
    	return $robots;
    });

    Looking forward to help you.

    D E
    Rank Math free

    Thanks for the response – it seems the above code doesn’t work, unfortunately.

    Alberto
    Rank Math business

    Hello,

    Then we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WP logins in the designated Sensitive Data section.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping 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 5 replies - 1 through 5 (of 5 total)

The ticket ‘Hide posts from sitemap that belong to certain category?’ is closed to new replies.