Remove WordPress Comments Author URL

Remove WordPress Comments Author URL
Remove WordPress Comments Author URL

Learn how to remove the author URL from WordPress comments to reduce spam and improve user experience. This beginner-friendly tutorial walks you through adding a simple code snippet to your theme’s functions.php file.

In WordPress, by default, the comment author’s name is linked to the URL they provide when leaving a comment. However, in some cases, you may want to remove this URL and display only the author’s name without any links. This can help reduce spam and ensure a cleaner comments section. Below is a simple way to achieve this by using a WordPress filter.

Removing the Author URL from Comments

To remove the URL associated with the comment author’s name, you can use the get_comment_author_link filter. This filter allows you to modify the output of the comment author link. In the following example, we use this filter to return only the author’s name, without the link to their website.

/**
 * Remove the URL from the comment author link.
 *
 * This function modifies the comment author link by returning only the
 * author's name, without the associated URL.
 *
 * @param int $comment_ID The comment ID.
 * @return string The comment author name without the URL.
 */
function remove_author_url( $comment_ID = 0 ) {
    // Retrieve the comment object using the comment ID
    $comment = get_comment( $comment_ID );
    
    // Return only the author name without the URL
    return get_comment_author( $comment );    
}

// Apply the filter to modify the comment author link
add_filter( 'get_comment_author_link', 'remove_author_url' );

How It Works

The code above achieves the following:

  • Step 1: The remove_author_url function retrieves the comment using get_comment() and then returns only the author’s name using the get_comment_author() function.
  • Step 2: The add_filter() function is used to hook into the get_comment_author_link filter. This ensures that instead of returning the author’s name as a hyperlink (which links to the author’s website), it returns just the author’s name.

As a result, the comment author’s name will be displayed in the comments section without any associated links to their URL, helping reduce potential spam or unwanted links on your website.

Conclusion

By using the simple filter provided above, you can remove the author’s URL from the WordPress comments section while still displaying the author’s name. This is a great way to keep your comments section clean, professional, and free from unwanted links. Simply add the provided code to your theme’s functions.php file or a custom plugin, and you’re all set!

Next: WordPress 404 Redirect to Home

Leave a Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top