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 someone might provide me with something that may do the job for me.
Thank you so much in advance!
add_filter( 'the_content', 'my_string_replacements');
function my_string_replacements ( $content ) {
if ( ! is_admin() && is_main_query() ) {
return preg_replace('/<a(.*href=".*\/go\/pluto\/?".*)>/', '<a$1 rel="nofollow">', $content );
}
return $content;
}