Aleš Sýkora / November 11, 2019 / 0 comments
Comments Shortcode for Content Templates
1 min read / WordPress / Share on: Twitter, LinkedIn, Facebook
Post summary: Display comments section whetever you want.
The challenge: display comments section in Bootstrap grid in content template of custom post type.
The solution: create custom shortcode for calling comments.php template.
The code:
function comments_template_shortcode() {
ob_start();
comments_template( '/comments.php' );
$cform = ob_get_contents();
ob_end_clean();
return $cform;
}
add_shortcode( 'comments-template', 'comments_template_shortcode' );
How to: Put this code in Toolset > Settings > Custom Code and activate it. Then use comments-template shortcode in your content template.
Fuel my passion for writing with a beer🍺
Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻