WORDPRESS - Oxygen - toolset

Comments Shortcode for Content Templates

Author: Aleš Sýkora, 11. 11. 2019

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.