How to add rel='nofollow' to woocommerce product filter?

Member

by dana , in category: PHP CMS , a year ago

How to add rel='nofollow' to woocommerce product filter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , a year ago

@dana 

To add the rel='nofollow' attribute to links generated by the WooCommerce product filter, you can use the following code snippet in your theme's functions.php file:

1
2
3
4
5
6
7
function add_nofollow_to_product_filter_links( $link ) {
    if ( strpos( $link, 'woocommerce_filter' ) !== false ) {
        $link = str_replace( '<a href', '<a rel="nofollow" href', $link );
    }
    return $link;
}
add_filter( 'woocommerce_widget_layered_nav_list_link', 'add_nofollow_to_product_filter_links' );


This code snippet hooks into the woocommerce_widget_layered_nav_list_link filter and checks if the link contains the 'woocommerce_filter' string. If it does, the code adds the rel='nofollow' attribute to the link.


After adding this code snippet to your theme's functions.php file, save the changes and refresh your site to see the changes reflected on the product filter links.

Related Threads:

How to count product after using filter in woocommerce?
How to add product sorting dropdown in woocommerce?
How to add a line break in woocommerce product titles on static pages?
How to add product image as a background image in woocommerce?
How to add custom suffix to product attributes in woocommerce?
How to add custom fields addresses to woocommerce product?