How to Change Avatar Size in wp_list_comments in WordPress

Home » Snippets » How to Change Avatar Size in wp_list_comments in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

WordPress comments are an integral part of user engagement on many websites. They facilitate conversation, feedback, and opinions. However, it’s important to ensure that the visual elements of your comment section are aesthetically pleasing and functional. The avatar size is one such element that can greatly affect the appearance of your comment section. In this article, we will discuss how to change the default avatar size in the wp_list_comments function in WordPress.

					function wpturbo_custom_comment_avatar( $args ) {
    $args['avatar_size'] = 80;
    return $args;
}
add_filter( 'wp_list_comments_args', 'wpturbo_custom_comment_avatar' );
				

The wp_list_comments() function is a built-in WordPress function that displays comments on a blog post or page. By default, the function displays a small 50×50 pixel avatar next to the comment author’s name. However, in some cases, you may want to increase or decrease the size of these avatars.

The code snippet provided shows how to change the size of these avatars to 80×80 pixels. The first line defines a new function called wpturbo_custom_comment_avatar() that accepts an array of arguments for the wp_list_comments() function.

Next, we set the avatar_size argument to a value of 80. This updates the size of the avatar to 80×80 pixels.

Finally, we hook this function into the wp_list_comments_args filter using the add_filter() function. Whenever the wp_list_comments() function is called, WordPress will execute this filter to modify the arguments passed to the function. Our custom function is responsible for modifying the avatar_size argument, and the updated value will be used when the comments are displayed on the page.

Overall, this code snippet provides an easy way to adjust the size of avatars in WordPress comments using the built-in wp_list_comments() function.

Register an account to save your snippets or go Pro to get more features.