Customize WordPress Comments template

By default you use the following function in order to display the template used for the comments :

<?php comments_template(); ?>

You may disable the addition of comments using the administration panel under each page configuration.

However if you need more freedom on interacting with the template you will need to take control over the function or use a different method.

The above function will display the number of comments added, the author name above each comment, the comment itself and the posted date. Optionaly the form to add a comment.

If you only need to display comments and nothing else then use the following lines :

$args = array(
	'status' => 'approve',
	'number' => '15', // whatever number of comments you wish to display.
	'post_id' => 18, // use post_id, not post_ID - replace 18 by your post ID

$comments = get_comments($args);

// Browse all comments one by one and display the content :
foreach ($comments as $comment) :


You might also like using the function : wp_list_comments(), but I thought using the get_comments will get us straight to the point on displaying exactly what we need.

For more information :

Leave a Reply

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

Want more information?

Related links will be displayed within articles for you to pick up another good spot to get more details about software development, deployment & monitoring.

Stay tuned by following us on Youtube.

%d bloggers like this: