CallBack Better WordPress Comments Template – Customize WordPress Comments

Please log in or register to like posts.

CallBack Better WordPress Comments Template – Customize WordPress Comments

WordPress CommentsWordPress Basically OpenSource Web Application. The WordPress Content Management System Is The Perfect For Start Blogging. Here WordPress Developer’s Can Change The WordPress Functions Using functions.php WordPress Theme File. WordPress Providing There Design For Making More Useful Functions With PHP, MYSQL Language. WordPress CallBack Function Usage For Call Others Theme Template File Into WordPress Default Theme File Location. You Can Develop More Theme Functionality.

The WordPress Comments template is not only one of the more complicated steps when creating a WordPress theme, but the default comments code is also quite complicated to customize. If you are a theme developer and have gotten stuck trying to customize your comments to make them look the way you want, but can’t because you need to add extra div classes or have to remove some, then you need to check out this post. I will show you how to easily create a custom call-back template that WordPress will use for your comment structure.

Better WordPress Comments

If you love the WordPress comment system but you want complete control over all the div containers and classes that make up each comment, you’ll have to create a new file with your custom comment code and then add a callback function to your comments.php file to use your new comments template.

WordPress Comments

we need to make a file in the theme folder e.g wp-content/themes/themename/custom-comment/better-comments.php then past this below code to created file better-coments.php file.

function better_comments( $comment, $args, $depth ) {
	global $post;
	$author_id = $post->post_author;
	$GLOBALS['comment'] = $comment;
	switch ( $comment->comment_type ) :
		case 'pingback' :
		case 'trackback' :
		// Display trackbacks differently than normal comments. ?>
	<li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
		<div class="pingback-entry"><span class="pingback-heading"><?php esc_html_e( 'Pingback:', 'twenties' ); ?></span> <?php comment_author_link(); ?></div>
		default :
		// Proceed with normal comments. ?>
	<li id="li-comment-<?php comment_ID(); ?>">
		<article id="comment-<?php comment_ID(); ?>" <?php comment_class('clr'); ?>>
			<div class="comment-author vcard">
				<?php echo get_avatar( $comment, 45 ); ?>
			</div><!-- .comment-author -->
			<div class="comment-details clr">
				<header class="comment-meta">
					<cite class="fn"><?php comment_author_link(); ?></cite>
					<span class="comment-date">
					<?php printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
						esc_url( get_comment_link( $comment->comment_ID ) ),
						get_comment_time( 'c' ),
						sprintf( _x( '%1$s', '1: date', 'twenties' ), get_comment_date() )
					); ?> <?php esc_html_e( 'at', 'twenties' ); ?> <?php comment_time(); ?>
					</span><!-- .comment-date -->
				</header><!-- .comment-meta -->
				<?php if ( '0' == $comment->comment_approved ) : ?>
					<p class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'twenties' ); ?></p>
				<?php endif; ?>
				<div class="comment-content entry clr">
					<?php comment_text(); ?>
				</div><!-- .comment-content -->
				<div class="reply comment-reply-link">
					<?php comment_reply_link( array_merge( $args, array(
						'reply_text' => esc_html__( 'Reply to this message', 'twenties' ),
						'depth'      => $depth,
						'max_depth'	 => $args['max_depth'] )
					) ); ?>
				</div><!-- .reply -->
			</div><!-- .comment-details -->
		</article><!-- #comment-## -->
	endswitch; // End comment_type check.

callback the new better-comments function in your normal comments.php file within the wp_list_comments array. Now we need to include this file from comments.php in the theme folder. Go to your wordpress functions file and copy past the below tag.

// Display comments
wp_list_comments( array(
	'callback' => 'better_comments'
) );

Now Save It and visit a post there have comments.  As opposed to just using the wp_list_comments function you can now edit all the code that will show up with each comment. [ads]

Highlight Author Comments

If you check out the better-comments code you can see that I’ve added “comment_class” to the main li. This will add special classes to your comments, such as a class for the post author. This is added by WordPress by default, but I thought it was worth a mention in this post ? below a example:

.bypostauthor {background: #ffff99;}

You can change the custom comment template default author or users Gravatar. If a user wasn’t set there profile picture, here you can put a logo of your website or cartoon avatar. If you look at the better-comments code you will also notice that I’ve included a url to a custom default gravatar. You can easily change the URL and add your own default Gravatar to your theme or you can remove it completely to show the default WordPress gravatar. Find and edit the following line:

<?php echo get_avatar( $comment, $size = '45', $default = get_bloginfo('stylesheet_directory').'/images/default-avatar.png' ); ?>

upload a png image file in your theme folder location wp-content/themes/themename/images. after you uploaded the File then the default gravater will change with your upload image.

For More WordPress Custom Functions And Tricks You and Touch Them From Below Link.

The WordPress Title Limit Characters Function Without Plugin
How To Change Default Role Name in WordPress User Profile
How To Make WordPress Post Views Count Without Plugin – WordPress
How To Highlight Author Comment in WordPress Using Only CSS
10+ Most Wanted WordPress Tips, Tricks, and Hacks – HowTrick
TrickBD WordPress Theme Download For Free – Nulled
How to Fix WordPress 404 Post Returning Error Issue
How to fix Establish Database Connection in WordPress
What is Internal server error and how to fix – WordPress
How To Display Random Posts in WordPress – Coding


Nobody liked ?

Leave a Reply

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