How to add nofollow to frontpage only? (Woocommerce products, internal links)

158 Views Asked by At

Currently it add nofollow at all products across website, how to make it at is_front_page() only?..

function woocommerce_template_loop_product_title() {
echo '<p class="name product-title ' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '"><a href="' . get_the_permalink() . '" rel="nofollow">' . get_the_title() . '</a></p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

}

1

There are 1 best solutions below

0
Mel On

Change the value of your rel attribute. So, when the user is at the frontpage, rel will have a value of nofollow. Otherwise, the value will be "" empty.

<?php

function woocommerce_template_loop_product_title() {

// Add the $nofollow
$nofollow = "";
if(is_front_page() ){
    $nofollow = "nofollow"; 
}

echo '<p class="name product-title ' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '"><a href="' . get_the_permalink() . '" rel='.$nofollow.'>' . get_the_title() . '</a></p>';
?>