To show a list of recent comments without using a plugin in WordPress, you can use the wp_list_comments function and customize it to your needs.
Here’s an example of how you can use the wp_list_comments function to show a list of the most recent comments on your WordPress site:
// Show recent comments list
// More snippets at wpunplugged.com
<ul>
<?php
$args = array(
'number' => 10, // Number of comments to show
'status' => 'approve', // Only show approved comments
'type' => 'comment', // Only show regular comments, not pingbacks or trackbacks
);
wp_list_comments( $args );
?>
</ul>
This code will show a list of the 10 most recent comments on your WordPress site. The comments will be ordered by date, with the most recent comments appearing first.
If you want to customize the output of the comments, you can use the callback argument in the wp_list_comments function. This argument allows you to specify a custom callback function that will be used to output the comments.
Here’s an example of how you can use a custom callback function to customize the output of the comments:
// Show recent comments list
// More snippets at wpunplugged.com
<ul>
<?php
$args = array(
'number' => 10, // Number of comments to show
'status' => 'approve', // Only show approved comments
'type' => 'comment', // Only show regular comments, not pingbacks or trackbacks
'callback' => 'my_custom_comment_callback', // Custom callback function
);
wp_list_comments( $args );
?>
</ul>
<?php
function my_custom_comment_callback( $comment, $args, $depth ) {
?>
<li>
<?php comment_author_link(); ?>
<?php comment_text(); ?>
</li>
<?php
}
?>
This code will show a list of the 10 most recent comments on your WordPress site, using the custom callback function to output the comments. You can customize the callback function to your needs to control the output of the comments.
To remove query variables or version numbers from styles or scripts in WordPress, you can use the style_loader_src and script_loader_src filters in your theme’s functions.php
To display a list of bbPress joined groups in WordPress, you can use the bbp_get_user_groups() function. This function returns an array of group objects for
To invalidate usernames with spaces in BuddyPress, you can use the bp_core_validate_user_signup filter. This filter allows you to modify the validation error messages for user
How to show recent comments list in WordPress
To show a list of recent comments without using a plugin in WordPress, you can use the
wp_list_commentsfunction and customize it to your needs.Here’s an example of how you can use the
wp_list_commentsfunction to show a list of the most recent comments on your WordPress site:This code will show a list of the 10 most recent comments on your WordPress site. The comments will be ordered by date, with the most recent comments appearing first.
If you want to customize the output of the comments, you can use the
callbackargument in thewp_list_commentsfunction. This argument allows you to specify a custom callback function that will be used to output the comments.Here’s an example of how you can use a custom callback function to customize the output of the comments:
This code will show a list of the 10 most recent comments on your WordPress site, using the custom callback function to output the comments. You can customize the callback function to your needs to control the output of the comments.
Share this post
You might also like...
How to remove query variables / version numbers from style or script in WordPress
To remove query variables or version numbers from styles or scripts in WordPress, you can use the style_loader_src and script_loader_src filters in your theme’s functions.php
How to display a list of bbPress joined groups in WordPress
To display a list of bbPress joined groups in WordPress, you can use the bbp_get_user_groups() function. This function returns an array of group objects for
How to invalidate username with spaces in BuddyPress
To invalidate usernames with spaces in BuddyPress, you can use the bp_core_validate_user_signup filter. This filter allows you to modify the validation error messages for user