Aleš Sýkora wrote

Comments Shortcode for Content Templates

11. 11. 2019 in

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.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Oxygen Front-end styles in Gutenberg
WARNING: I can’t figure how to make it working currently. If you have any idea, please put in in the comments below. You may want to display the content when editing in Gutenberg editor with your frontend Oxygen Styles included. It is possible with But the challenge is that Oxygen is creating CSS files for […]
Read More
Aleš Sýkora wrote
Remove Archive Title Prefix in Astra Theme
29. 8. 2019 in
You can use this as a plugin to disable the Archive: Category: Tag: prefix in Astra Theme archives.
Read More
Aleš Sýkora wrote
Display all WooCommerce categories and their products inside
11. 2. 2021 in
If you need to display all your WooCommerce categories in the list and their products inside, you can use mine code. For example you need to create one page layout for food felivery. Use my second tutorial, if you like to display all subcategories and its products on parent category archive. Page = Food Delivery […]
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram