The comment_author_link_rel WordPress PHP filter allows you to modify the rel attributes of the comment author’s link.
Usage
add_filter('comment_author_link_rel', 'your_custom_function', 10, 2);
function your_custom_function($rel_parts, $comment) {
// your custom code here
return $rel_parts;
}
Parameters
$rel_parts(string[]): An array of strings representing the rel tags which will be joined into the anchor’s rel attribute.$comment(WP_Comment): The comment object.
More information
See WordPress Developer Resources: comment_author_link_rel
Examples
Add a custom rel attribute
Add a custom rel attribute to the comment author’s link.
add_filter('comment_author_link_rel', 'add_custom_rel_attribute', 10, 2);
function add_custom_rel_attribute($rel_parts, $comment) {
$rel_parts[] = 'custom-rel';
return $rel_parts;
}
Remove the ‘nofollow’ rel attribute
Remove the ‘nofollow’ rel attribute from the comment author’s link.
add_filter('comment_author_link_rel', 'remove_nofollow_attribute', 10, 2);
function remove_nofollow_attribute($rel_parts, $comment) {
$rel_parts = array_diff($rel_parts, ['nofollow']);
return $rel_parts;
}
Replace ‘external’ rel attribute with ‘internal’
Replace the ‘external’ rel attribute with ‘internal’ for comment author’s link.
add_filter('comment_author_link_rel', 'replace_external_with_internal', 10, 2);
function replace_external_with_internal($rel_parts, $comment) {
if (($key = array_search('external', $rel_parts)) !== false) {
$rel_parts[$key] = 'internal';
}
return $rel_parts;
}
Set rel attributes based on comment author role
Set rel attributes based on the comment author’s user role.
add_filter('comment_author_link_rel', 'set_rel_by_author_role', 10, 2);
function set_rel_by_author_role($rel_parts, $comment) {
$user = get_user_by('email', $comment->comment_author_email);
if ($user && in_array('administrator', $user->roles)) {
$rel_parts[] = 'admin';
}
return $rel_parts;
}
Remove all rel attributes
Remove all rel attributes from the comment author’s link.
add_filter('comment_author_link_rel', 'remove_all_rel_attributes', 10, 2);
function remove_all_rel_attributes($rel_parts, $comment) {
return [];
}