shortcode – wpv-post-comments

Sometimes it is useful to add WordPress post Comments in a Content Template or a View. It is possible to build a shortcode to display it:

// Display post Comments shortcode
add_shortcode('wpv-post-comments', 'my_post_comments');
function my_post_comments() {
       ob_start();
       comments_template();
       $data = ob_get_clean();
       return $data;
}


comments_template() reference: https://developer.wordpress.org/reference/functions/comments_template/

Then I can use this shortcode anywhere:

[wpv-post-comments]



You can find this solution on this Toolset forum thread:

https://toolset.com/forums/topic/show-comments-and-comments-form-within-a-view/

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>