How To Change WooCommerce Add To Cart NoFollow DoFollow

Most of the products in my Adventurer’s Loot D&D Dice Woocommerce have the ‘Add to Cart’ button variables tagged as rel “nofollow” tag in the markup.  This isn’t particularly good for SEO and it can be tricky to change.  After some searching around on GitHub, I found a solution to the following question.

How can I change the WooCommerce Add To Cart rel attribute from “nofollow” and “dofollow”?

I want to go from here:

 

To Here:

add-to-cart-no-follow

 

What worked for me was:

First installing and activating the child theme first. This should help with any theme updates overwriting your work.

After that under the functions.php file located in your child theme, add this code:

 

add_filter( 'woocommerce_loop_add_to_cart_link', 'add_to_cart_dofollow', 10, 2 );
function add_to_cart_dofollow($html, $product){
	$html = sprintf( '%s',
		esc_url( $product->add_to_cart_url() ),
		esc_attr( isset( $quantity ) ? $quantity : 1 ),
		esc_attr( $product->get_id() ),
		esc_attr( $product->get_sku() ),
		esc_attr( isset( $class ) ? $class : 'button' ),
		esc_html( $product->add_to_cart_text() )
	);
	return $html;
}

As you can see in the example above, the change has taken effect.

If you’re looking to remove your add to cart from the search results you can consider the adding the noindex to your HTaccess file.

Hope you found this helpful!

Mike @ Eurisko

Mike @ Eurisko

Mike Bullen is a digital marketing strategist and serial inventor/entrepreneur who combines a solid digital background with the technical know-how to deliver real results.With a passion for the Perth Start-Up scene, Mike launched Eurisko as a digital marketing consultancy and usually has a project or two of his own on the side, where he hones his results-driven approach.Mike’s ability to generate more leads, more sales and ultimately more revenue for his clients is a testament to his proficiency with SEM, SEO, web analytics, marketing automation, UX / CX, email marketing, and social media marketing, including social advertising, and earned media amplification.Mike’s focus when delivering projects is to optimize & amplify digital experiences to generate more leads, more sales and more revenue.

Eurisko

Eurisko is a digital marketing agency in Australia that helps local businesses drive more traffic, engage more customers and generate more revenue. Regardless of size, business model or industry you are in, as your online marketing agency, we have the experience to tailor the right digital marketing strategy to amplify and optimise your online campaigns. Our in-depth knowledge garnered from our many years’ experience within the digital marketing industry translates to excellent, meaningful and measurable results for our clients.

Recent Posts by

Mike @ Eurisko