Below, you’ll find a detailed guide on how to add the Better Recent Comments Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Better Recent Comments Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Better Recent Comments Plugin and the shortcodes it provides:
"Better Recent Comments is a user-friendly WordPress plugin that enhances the visibility of the latest comments on your blog, improving engagement and interaction."
- [better_recent_comments]
Better Recent Comments [better_recent_comments] Shortcode
The Better Recent Comments plugin shortcode is a powerful tool for displaying recent comments. It utilizes the shortcode function to fetch and display the most recent comments based on the specified attributes. This shortcode retrieves the default arguments, processes them, and returns the recent comments. This allows for easy and flexible customization of your recent comments display.
Shortcode: [better_recent_comments]
Examples and Usage
Basic example – The shortcode displays the recent comments on the website using default parameters.
[better-recent-comments]
Advanced examples
Display the recent comments with a specific number of comments and order. The ‘number’ attribute controls the number of comments to show, and the ‘order’ attribute controls the order of comments. ‘ASC’ for ascending order and ‘DESC’ for descending order.
[better-recent-comments number="5" order="ASC"]
Display the recent comments excluding certain users. The ‘exclude_users’ attribute allows you to exclude comments from specific users by their IDs.
[better-recent-comments exclude_users="2,3"]
Display the recent comments from a specific post. The ‘post_id’ attribute allows you to display comments from a specific post by its ID.
[better-recent-comments post_id="10"]
Combine multiple attributes to display recent comments in a specific way. In this example, we display 5 recent comments in ascending order, excluding users with IDs 2 and 3, from post with ID 10.
[better-recent-comments number="5" order="ASC" exclude_users="2,3" post_id="10"]
PHP Function Code
In case you have difficulties debugging what causing issues with [better_recent_comments]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( self::SHORTCODE, [ $this, 'shortcode' ] );
Shortcode PHP function:
function shortcode( $atts, $content = '' ) {
$atts = shortcode_atts( Util::default_shortcode_args(), $atts, self::SHORTCODE );
return Util::get_recent_comments( $atts );
}
Code file location:
better-recent-comments/better-recent-comments/src/Plugin.php
Conclusion
Now that you’ve learned how to embed the Better Recent Comments Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply