Problem:
I would like to change the position of where the comments are displayed,
and display them somewhere inside a content template.
I thought about one type of solution, I added a shortcode in functions.php:
add_shortcode( 'display_comments', 'display_comments_shortcode' );
function display_comments_shortcode() {
comments_template();
}
then I added the shortcode somewhere inside the content template, but the comments where displayed at the top of the page, above everything in the page, and not where I located the shortcode.
Solution:
The WordPress function comments_template() will output the HTML codes directly, in the shortcode PHP function, you will need to setup it as return, so you can modify your codes as below:
add_shortcode( 'display_comments', 'display_comments_shortcode' ); function display_comments_shortcode() { ob_start(); comments_template(); $res = ob_get_contents(); ob_end_clean(); return $res; }
Relevant Documentation:
http://php.net/manual/en/function.ob-get-contents.php
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Hong_Kong (GMT+08:00)
This topic contains 4 réponses, has 4 voix.
Last updated by sandeepc Il y a 7 années et 10 mois.
Assisted by: Luo Yang.