Add-to-cart index by Google

#1098570
  • Hi all I still have this issue with Rank Math.

    I have bunch of URL with ?add-to-cart indexed by Google.

    I have already put in the function.php this code suggested by you:


    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    // Get the current page URL
    $current_url = home_url( $_SERVER['REQUEST_URI'] );

    // Define the string to check for in the URL
    $string_to_check = '?add-to-cart';

    // Check if the current URL contains the specific string
    if ( strpos( $current_url, $string_to_check ) !== false ) {
    // Change the robots tag to noindex
    $robots['index'] = 'noindex';
    }

    // Return the modified robots array
    return $robots;
    });

    But he issue still on it.

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

    We apologize for the issue you are facing with the URLs containing ?add-to-cart still being indexed by Google. It seems that the code you added to your functions.php file is intended to set those URLs to noindex, but it may not be functioning as expected.

    Here are a few things you can check:

    1. Clear Cache: If you are using any caching plugins, make sure to clear the cache after making changes to your functions.php file. Sometimes, cached versions of your pages can still be served to search engines.
    2. Check for Conflicts: Ensure that there are no other plugins or settings that might be overriding the noindex directive. You can use the Health Check plugin to help identify any conflicts.
    3. Verify Robots Meta Tag: After implementing the code, check the source code of the affected pages to ensure that the “ tag is present. This will confirm that your code is working correctly.
    4. Google Search Console: Use Google Search Console to request a re-crawl of the affected URLs after making these changes. This can help speed up the process of removing them from Google’s index.

    If you’ve checked all of these and the issue persists, please reply to this ticket with your site URL so that a human agent from our support team can assist you further. Thank you for raising this concern!

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

    This is an automated reply from Rank Math Support Bot. Your ticket has been assigned to a human agent and we will get back to you shortly.

    Hello,

    Thank you for contacting Rank Math support, and we apologise for the inconvenience.

    By default, Rank Math automatically adds noindex to the cart pages to stop the Google search engine from indexing your cart. There’s no need for Google to index these pages, as the page is unique to each user of your site.

    If Google has already indexed the page – which it has – the rule in the robots.txt file will not remove the page from Google; you will have to use the Google Removal tool to remove the URL from Google’s index.

    Then you can use the following filter on your website to set the pages to noindex so that Google doesn’t index them on SERPs:

    
    add_filter( 'rank_math/frontend/robots', function( $robots ) { 
        $url = home_url( $_SERVER['REQUEST_URI'] ); 
        if ( strpos( $url, '?add-to-cart=' ) !== false ) { 
            $robots["index"] = 'noindex'; 
            $robots["follow"] = 'nofollow'; 
        } 
        return $robots; 
    });

    You can follow this guide to apply the filter correctly: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    To figure out how Google is discovering those other URLs, you should use the URL inspection tool of your GSC account to check the URLs and look out for the referring page where they are coming from or how Google is discovering them.

    You can track those URLs via the referring page to determine how Google crawled them.

    Hope that helps.

    Thank you.

    Any news about the issue?

    Now I have those page be indexed by Google:

    https://vinadoo.com/enotecacattaneo/prodotto/clos-de-gamot-cahors/?add_to_wishlist=1902&_wpnonce=d3052c0f55

    I have a bunch of ?add_to_wishlist indexed

    Hello,

    Apologies for the delay, as this ticket seems to have been stuck in our drafts section for some reason.

    Your add-to-cart URLs are already set to noindex.

    Regarding the ?add_to_wishlist, you can update the filter with this one:

    add_filter( 'rank_math/frontend/robots', function( $robots ) { 
        $url = home_url( $_SERVER['REQUEST_URI'] ); 
        if ( strpos( $url, '?add-to-cart=' ) !== false || strpos($url,'?add_to_wishlist=')) { 
            $robots["index"] = 'noindex'; 
            $robots["follow"] = 'nofollow'; 
        } 
        return $robots; 
    });

    Once done, clear your website’s cache and revalidate the issue in your Google Search Console account and give Google some time to recrawl your site.

    validate

    Looking forward to helping you.

    Federico Porta
    Rank Math free

    Hi Reinelle, thanks for your reply.

    Why this issue happen also for the add_to_whislist?

    I don’t understand why Google index those page. Looking at the URL inspection tool the Canonical is set ad self.

    Hello,

    When you’re using E-commerce features on your site, those such links can be generated on the referring page when you inspect them in your Google Search Console tool, even if they are useless for a crawler and can waste server resources.

    Those links can be present in buttons, like add to cart or add to wishlist where Google can discover them.

    Their canonical URL are self-referencing since they are set to index, which is why forcing them to noindex removes the canonical and informs search engines not to crawl those links.

    Looking forward to helping you.

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

You must be logged in to reply to this ticket.