Help with no-index function :)

#754581
  • Resolved Anonymous
    Rank Math free

    I’m using the follow script to no-index job offers that get expired.

    add_filter('rank_math/frontend/robots', function ($robots) {
    if (is_singular('job')) {
    $job = wpjb_get_object_from_post_id(get_the_ID(), 'job');

    if ($job && $job->expired()) {
    // Adiciona 'noindex' ao array de diretivas meta robots
    $robots = array_diff($robots, array('index'));
    $robots[] = 'noindex';
    }
    }

    return $robots;
    });

    And it actually put’s the page with no-index, but it doesn’t get removed from the sitemap. When I edit the page, it shows ‘index’ in the rankmath (perhaps, it’s noindex in the reality) gutenberg feature – what can I do to improve the code?

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

    I apologize for the issue you are facing with the no-index function in Rank Math. It seems like the page is not getting removed from the sitemap even though it is set to no-index.

    To ensure that the page is correctly removed from the sitemap, you can try the following steps:

    1. Check if the robots meta tag is correctly set to no-index in the Rank Math settings for the specific post. You can navigate to Rank Math SEO → Advanced tab in the post editing screen to verify this setting.

    2. If the robots meta tag is set to no-index but the page is still appearing in the sitemap, you can try adding a filter to exclude pages with a no-index directive from the sitemap. Here is an example of how you can modify your code snippet to exclude pages with a no-index directive from the sitemap:

    add_filter('rank_math/sitemap/post_include', function ($include, $post_id) {
        $robots = get_post_meta($post_id, 'rank_math_robots', true);
    
        if ($robots === 'noindex') {
            return false; // Exclude the post from the sitemap
        }
    
        return $include;
    }, 10, 2);

    By adding this filter, pages with a no-index directive will be excluded from the sitemap generated by Rank Math.

    If you continue to experience issues or need further assistance, please feel free to reply to this ticket, and a human agent from the Rank Math Support team will assist you promptly.

    Thank you for reaching out with your concern.

    Sources:
    How to NoIndex All Posts in a Category » Rank Math
    How to Make Your Theme Rank Math Compatible » Rank Math
    How to Noindex URLs With Rank Math » Rank Math
    How to Fix Submitted URL Marked ‘NoIndex’ Error » Rank Math
    Why the Sitemap_Index.xml is Throwing a 404 Error » Rank Math

    Hello,

    Thank you for contacting Rank Math support.

    Please note that the filter sets the posts as Noindex in the front end. They will still be set to Index in the backend and will be included in the sitemap.

    Instead of using the filter to set the expired post to Noindex, you can use the Unpublish when Expired option of the JobPosting Schema of our plugin to unpublish the post and remove it from the sitemap. https://rankmath.com/kb/jobposting-schema/#unpublish-when-expired

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

    Anonymous
    Rank Math free

    Hey Jaideep Asrani, that’s a good suggestion, but we don’t want to remove the page.

    Anonymous
    Rank Math free

    where do i add this filter?

    Hello @Tiagoandre,

    The other alternative is to exclude those expired Job listings manually from the sitemap at WordPress Dashboard → Rank Math SEO → Sitemap Settings → General.

    https://rankmath.com/wp-content/uploads/2023/09/Enter-the-ID-into-the-field-and-Save-Changes.png

    Enter the ID of the expired listings into the field. Remember to separate multiple IDs with a comma. Once done, scroll down and click Save Changes.

    You can refer to this guide: https://rankmath.com/kb/exclude-content-from-sitemap/#exclude-specific-posts-and-pages

    Please note that it is totally okay for the robots tag to be set to noindex only on the frontend as Search Engine do not have access to the backend and will not index those pages because of the tag.

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

    Hello @Leesa-7410,

    Here’s how you can add filter/hook to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

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

    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 6 replies - 1 through 6 (of 6 total)

The ticket ‘Help with no-index function :)’ is closed to new replies.