Forked from EricBusch/add-rel-nofollow-to-woocommerce-product-links.php
Created
July 25, 2017 12:22
-
-
Save EricBusch/5d730a175d3d6058eef4ae19b92e634e to your computer and use it in GitHub Desktop.
This code allows you to add a rel="nofollow" to your WooCommerce products that appear in the loop. [datafeedr]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove the woocommerce_template_loop_product_link_open() function from the | |
* WooCommerce "woocommerce_before_shop_loop_item" action. | |
* | |
* @see remove_action() | |
*/ | |
add_action( 'wp_head', 'mycode_remove_woocommerce_template_loop_product_link_open' ); | |
function mycode_remove_woocommerce_template_loop_product_link_open() { | |
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); | |
} | |
/** | |
* Attach our own function to use in place of the woocommerce_template_loop_product_link_open() function to | |
* the WooCommerce "woocommerce_before_shop_loop_item" action. | |
* | |
* @see get_the_permalink() | |
*/ | |
add_action( 'woocommerce_before_shop_loop_item', 'mycode_template_loop_product_link_open', 20 ); | |
function mycode_template_loop_product_link_open() { | |
echo '<a href="' . get_the_permalink() . '" rel="nofollow" class="woocommerce-LoopProduct-link">'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment