-
Can you please tell me how can I stop indexing of product filters in woocommerce shop?
-
Hello,
Thanks for contacting us, and sorry for any inconvenience that might have been caused due to that.
The question was little unclear. I believe you wanted to ask to stop indexing of product filters in Google Search? If yes, then please add below code in your theme
functions.php
// Noindex filter queries add_filter( 'rank_math/frontend/robots', function( $robots ) { $url = home_url( $_SERVER['REQUEST_URI'] ); if (strpos($url,'?product_orderby=') !== false || strpos($url,'?product_view=') !== false || strpos($url,'?product_count=') !== false || strpos($url,'?product_order=') !== false ) { $robots['index'] = "noindex"; $robots['follow'] = 'nofollow'; }; return $robots; });
You can learn about how to add filters by going through this : 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.
Thank you.
Thank you for this recommendation of adding this code to php file.
And I will try to explain my problem a little bit better.
So, my WordPress site is built with Woocommerce plugin and Divi theme and it has additional plugin for product filtering which is consisted of brand, product category and price filter. I’m trying to eliminate generating additional indexable links every time when somebody hit any value in filter on category pages, in other words I don’t want to spend my site’s SEO crawl budget on filters.
So can you tell me please, now, after this explanation, would you still recommend applying the previously suggested code or it would need some adjustment?
Thank you
Hello,
Thank you for providing additional information.
Please share the website URL so that we can modify the above code. Also, please share the plugin name you’re using for additional filtering.
Looking forward to helping you.
Thank you
Hello,
The plugin that we use for product filtering is Filter Everything — WooCoomerce Product & WordPress Filter and the url of our page is https://musicwheel.hr/.
And I have one more question related to crawl budget. Is it needed to exclude filters in woo modules in Divi builder (order by price, order by popularity…) as well?
Thank you very much for your support.
Hello,
I have modified the code snippet to include some of the query strings:
// Noindex filter queries add_filter( 'rank_math/frontend/robots', function( $robots ) { $url = home_url( $_SERVER['REQUEST_URI'] ); if (strpos($url,'kategorije') !== false || strpos($url,'brandovi') !== false || strpos($url,'?product_count=') !== false || strpos($url,'?product_order=') !== false ) { $robots['index'] = "noindex"; $robots['follow'] = 'nofollow'; }; return $robots; });
Hope that helps. Please let us know if you have questions.
Great, thank you so much.
Do I nsed to replace home_url with https://musicwheel.hr?Hello,
No, you don’t have to replace the home_url in the filter. You can use it as it is or modify it to add more query strings.
Hope that helps. Let us know if you need any other assistance.
Is there any other way to implement previously suggested code on site? I tried with theme’s functions.php file and it broke my site.
Hello,
Other ways can be either working with your child theme’s
function.php
file or using a plugin like Code Snippets as mentioned in the KB below:
https://rankmath.com/kb/wordpress-hooks-actions-filters/Let us know how it goes. Looking forward to helping you.
Thank you.
I tried with child’s theme functions file at the end of the file. Does it matter where in the file is the code pasted?
Also, it doesn’t seems that it works because filters and add to cart button are still indexed.Hello,
It is advisable to add at the bottom as we’ll be sure that we didn’t by mistake messed up other codes. As the filters were already indexed, in the next crawl it will be removed. We don’t have specific time frame that when it will be crawled, it varies from weeks to month. So, I would suggest please wait until Google recrawls the website.
About add to cart getting indexed, you can add the following line in robots.txt file by navigating to Rank Math > General Settings > Edit robots.txt
Disallow: /*add-to-cart=*
Hope that helps, and please do not hesitate to let us know if you need our assistance with anything else.
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.
The ticket ‘Product filter indexing’ is closed to new replies.