I was doing some SEO tests for my e-commerce site and I noticed that there are several nofollow links. These are actually the add to cart links in the product loop, which is correct. However, there's one thing that doesn't add up: for variable products, that link doesn't add the product to the cart but instead leads to the product page. This way, we end up with many nofollow links to the product page on all the pages where the loop is present. This is very damaging for the SEO of my site. Is it possible to ask if there is a way to remove the nofollow from the add to cart buttons for variable products?
sorry, but that was not what I was referring to. the no follow link is the one in ALL product loops, not in the mini cart (see screenshot). please also check from the inspector and verify what you wrote in the previous message
Hey Co-Brains, Salient doesn't add that nofollow attribute explicity - it is added by default from WooCommerce. Overriding it would require the use of a filter from your child theme functions.php such as :
Perfect! It seems to be working perfectly, thank you very much! I slightly modified the code so that the function is applied only to variable products (more problematic links from an SEO perspective).
add_filter( 'woocommerce_loop_add_to_cart_link', 'add_to_cart_dofollow', 10, 2 );
function add_to_cart_dofollow($html, $product){
// Check if the product is of type 'variable'
if ( $product->is_type( 'variable' ) ) {
// Modify the HTML for the 'Add to Cart' link
$html = sprintf(
'<a rel="dofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">%s</a>',
esc_url( $product->add_to_cart_url() ), // URL for the 'Add to Cart' link
esc_attr( isset( $quantity ) ? $quantity : 1 ), // Quantity (default to 1)
esc_attr( $product->get_id() ), // Product ID
esc_attr( $product->get_sku() ), // Product SKU
esc_attr( isset( $class ) ? $class : 'button' ), // CSS class (default to 'button')
esc_html( $product->add_to_cart_text() ) // Text for the 'Add to Cart' link
);
}
return $html; // Return the modified or original HTML
}
Is there a possibility that this function can be integrated directly into the theme?
Hey Co-Brains! As of now I don't think this snippet will get implemented into the core of Salient, as it's a modification to the core of WooCommerce. It would be better if WooCommerce changed the output directly - I would suggest leaving a comment on one of the related github issues to get your +1 in for the idea.
Hi!
I was doing some SEO tests for my e-commerce site and I noticed that there are several nofollow links. These are actually the add to cart links in the product loop, which is correct. However, there's one thing that doesn't add up: for variable products, that link doesn't add the product to the cart but instead leads to the product page. This way, we end up with many nofollow links to the product page on all the pages where the loop is present. This is very damaging for the SEO of my site. Is it possible to ask if there is a way to remove the nofollow from the add to cart buttons for variable products?
Thank you
Have a nice day
Hi there,
Thanks for writing to us.
You can change the options from Salient > Woocommerce > General to change the add to cart click action :
Please let us know whether this was helpful.
I look forward to hearing from you.
Hi judith!
sorry, but that was not what I was referring to. the no follow link is the one in ALL product loops, not in the mini cart (see screenshot).
please also check from the inspector and verify what you wrote in the previous message
Thank you
Have a nice day
Attached files: Screenshot 2024-06-06 alle 12.06.37 PM.png
Hey Again,
Escalating this to the developer to check if there is a quick fix available for this.
Thanks.
ThemeNectar Support Team
Hi Tahir!
thanks for the reply!
i look forward to updates
thank you
have a nice day
Hey Co-Brains, Salient doesn't add that nofollow attribute explicity - it is added by default from WooCommerce. Overriding it would require the use of a filter from your child theme functions.php such as :
Kind regards
Perfect! It seems to be working perfectly, thank you very much! I slightly modified the code so that the function is applied only to variable products (more problematic links from an SEO perspective).
Is there a possibility that this function can be integrated directly into the theme?
Thank you
Have a nice day
Hey Co-Brains! As of now I don't think this snippet will get implemented into the core of Salient, as it's a modification to the core of WooCommerce. It would be better if WooCommerce changed the output directly - I would suggest leaving a comment on one of the related github issues to get your +1 in for the idea.
Kind regards