0

WordPress automatically adds rel="nofollow ugc" to all links posted in comments. In our case we use comments to link to relevant articles in a website and need them to be followed.

How to remove this automatic rel being added?

The function itself is setup in the core with: wp_rel_ugc()

There are older posts recommending this filter:

remove_filter( 'pre_comment_content', 'wp_rel_nofollow', 15 );

However that no longer seems to work.

I would like to disable this function altogether.

I looks like some effort was made to fix this in core, but this has not been implemented yet: Prevent tagging certain links in comments with rel="nofollow ugc"

1 Answer 1

1

This removes the tag before it displays the comment on the page. I tested it myself.

function remove_ugc_from_links($text) {
    // replace 'rel="ugc"' with an empty string
    $new_text = str_replace('rel="ugc"', '', $text);

    return $new_text;
}
// Hook our function to the 'comment_text' filter
add_filter( 'comment_text', 'remove_ugc_from_links');
6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.