Reputation: 17
I am trying to find a way to easily remove the nofollow attribute ONLY for all the internal links on my site (WordPress).
How can I do that?
Upvotes: 0
Views: 1276
Reputation: 1126
The snippet below will check the page content and comment fields so see if a string contains the site url and, if true, remove the any no-follow attribute if set. This is assuming the links are using an absolute path.
function remove_nofollow($string) {
$internal = get_site_url();
if ( str_contains( $internal, $string ) {
$string = str_ireplace(' rel="nofollow"', '', $string);
}
return $string;
}
add_filter('the_content', 'remove_nofollow');
add_filter('comment_text', 'remove_nofollow');
Upvotes: 0