remove meta robots for query parameters url

#988544
  • Resolved Ali Peyvandi
    Rank Math free

    In woocommerce I use filter and in google search console I see that the query parameters are indexed!
    urls is like this below:

    https://site.com/shop/page/2/?stock_status=instock&filter_cat=18%2C19%2C20%2C21&orderby=popularity

    I should noindex these urls. I can’t find that setting in rankmath panel.

    I find this code. it adds noindex meta robots tag but it dosen’t remove rankmath meta robots. how can I fix my code to do this?

    `
    function noindex_filtered_pages() {
    if (!empty($_GET)) {
    remove_action(‘rank_math/head’, ‘RankMathFrontendHead::robots’);
    echo ‘<meta name=”robots” content=”noindex, follow”>’;
    }
    }
    add_action(‘wp_head’, ‘noindex_filtered_pages’, 1);
    `

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

    I apologize for the issue you are facing with the indexing of query parameter URLs in Google Search Console. Thank you for raising this concern.

    To ensure that the noindex meta robots tag is applied correctly and that it removes the existing Rank Math meta robots, you can modify your code slightly. The goal is to ensure that the Rank Math robots action is removed before adding your custom meta tag. Here’s an updated version of your code:

    function noindex_filtered_pages() {
        if (!empty($_GET)) {
            // Remove Rank Math's robots action
            remove_action('rank_math/head', 'RankMathFrontendHead::robots');
            // Add custom noindex meta tag
            echo '';
        }
    }
    add_action('wp_head', 'noindex_filtered_pages', 1);

    Explanation:

    1. Remove Action: The remove_action function is used to remove the default Rank Math robots meta tag from the head section.
    2. Add Custom Meta Tag: The echo statement adds your custom noindex meta tag to the head section of the page.

    Important Note:

    • Make sure to test this code on a staging site first to ensure it works as expected without affecting other functionalities.
    • After implementing this change, it may take some time for Google to re-crawl and update the indexing status of these URLs.

    If you continue to experience issues or if there are specific technical problems on your site, please reply to this ticket with your site URL, and a human agent from the Rank Math Support team will assist you further.

    Thank you for your understanding!

    Sources:
    How to Make Your Theme Rank Math Compatible » Rank Math

    After I add new function that generated by AI I still see the rankmath robots meta tag

    Hello,

    Thank you for your patience.

    The first robots meta tag you marked from your screenshot is not coming from Rank Math.

    To determine which plugin/theme is generating it, please follow this troubleshooting guide:
    https://rankmath.com/kb/check-plugin-conflicts/

    Here is a video you can follow as well: https://www.youtube.com/watch?v=FcIWRhcUP2c

    Only the site admin would know, and your users won’t be affected by this troubleshooting.

    Now, you should use this code to set those filtered URLs to noindex and nofollow in Rank Math robots meta tag:

    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	$url = home_url( $_SERVER['REQUEST_URI'] );
    	if (strpos($url,'?stock_status=') !== false || strpos($url,'filter_cat=') || strpos($url,'?orderby=')) {
                    $robots['index'] = 'noindex';
                    $robots['follow'] = 'nofollow';
    	        return $robots;
            }
    	return $robots;
    });

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

    Looking forward to helping you.

    Your code works well thanks; so the meta tag is added by rankmath I think.

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

The ticket ‘remove meta robots for query parameters url’ is closed to new replies.