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
  • Are you sure? I can't find the wp_rel_ugc filter in the online documentation or the source code.
    – Pat J
    Commented Dec 27, 2023 at 2:21
  • I am testing this on a demo site now, I will figure it out for you. Commented Dec 27, 2023 at 2:30
  • I just posted a function that works, it removes the tag Commented Dec 27, 2023 at 2:36
  • 1
    This is working, I had to modify slightly because I wanted to remove nofollow as well: $new_text = str_replace('rel="nofollow ugc"', '', $text);
    – AJD
    Commented Dec 27, 2023 at 4:59
  • wp_rel_ugc: developer.wordpress.org/reference/functions/wp_rel_ugc
    – AJD
    Commented Dec 27, 2023 at 5:01

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.