WP 5.3 introduces new functions to add UGC attribute to links, and implements it to comments

Since version 1.5, WordPress has used the wp_rel_nofollow() function to add a “nofollow” attribute to links. Version 2.3 introduced wp_rel_nofollow_callback() as a callback function to handle that addition, so developers were able to programmatically add a “nofollow” rel attribute value to any link.

Google recently announced that the “ugc” link attribute value is now supported for user generated content, like comments.

UGC stands for User Generated Content, and the ugc attribute value is recommended for links within user generated content, such as comments and forum posts.

Source: Google Webmasters Blog, September 10, 2019

In WordPress 5.3, wp_rel_nofollow_callback() will be deprecated in favor of more generic callback function, wp_rel_callback(), which is now used to add other rel attribute values to a specified link.

wp_rel_callback() is used by the existing wp_rel_nofollow() function to add a single “nofollow” value, and with the new wp_rel_ugc() function, developers can add both “nofollow” and “ugc” values to the rel attribute.

Example: usage of wp_rel_ugc()

Add a “ugc” rel attribute value to a given link:

$link = '<a href="example.com">User generated link example</a>';
$ugc_link = wp_rel_ugc( $link );
echo $ugc_link;
// output: <a href="example.com" rel="nofollow ugc">User generated link example</a>

Implementation in comments

Starting in WordPress 5.3, links in comments and comment author URLs will use the rel="nofollow ugc" attribute by default.


For reference, see TracTrac An open source project by Edgewall Software that serves as a bug tracker and project management tool for WordPress. ticketticket Created for both bug reports and feature development on the bug tracker. #48022 and the related changeset [46349] in the WordPress code base.

#5-3, #dev-notes