I have some cloaking affiliate links to which i would like to add the attributes of nofollow
However, i’m looking for a way in coding that will allow me to target links that contain specific string, like **/go/brand
While searching, i found this code somewhere, but it didn’t work for me in functions.php, so i was hoping some of you guys might provide with something that might do the job for me. That would be much appreciated !
Thank you so much in advance !
[code]add_filter( ‘the_content’, ‘my_string_replacements’);
function my_string_replacements ( $content ) {
if ( ! is_admin() && is_main_query() ) {
return preg_replace(‘/<a(.*href=”.*/link/pluto/?”.*)>/’, ‘<a$1 rel=”nofollow”>’, $content );
}
return $content;
}
__(Added `[code]…[/code]