I have enabled comments for one of my custom post types.
The comments box appears on the front end but it right at the bottom of the <body> section and after any content within my content template. I found this code:-
add_shortcode( 'display_comments', 'display_comments_shortcode' );
function display_comments_shortcode() {
ob_start();
comments_template();
$res = ob_get_contents();
ob_end_clean();
return $res;
}
in this thread https://toolset.com/forums/topic/display-comments-at-the-middle-of-a-content-template/ . I added this to my functions file and added the shortcode to my CT at the required location and the comments box now appears where desired but it still also appears across the bottom. How do I remove this second instance please?
Comments are not part of the_content(), and that is what Content Templates replace.
Since your Theme provides a Comments template it will render where the Theme author defined.
You will need to either check Theme options or create a Child Theme to remove that.
I think easier is, apply some styles to add some space between content template (the_content) and the Comments Template, with CSS?
Adding space won't display it within the content of the content template (which is what is required). I'm using the Toolset Starter theme and I have a child starter in place. I've struggled to understand your response but am I right in understanding you mean I need to add one of the theme files into my theme child folder and amend it as required?
If so, could you clarify what I need to remove from which theme file to remove the second instance of comments please?
Well, if you use the Starter theme, I can suggest to add Toolset Layouts to the Plugins.
Then, you can display a Cell, which contains the comments form.
This can be placed anywhere, and the Content as well, along with all other subjects of Layouts.
If you use Content Templates only, you need to rely on what the Theme defines - it will not be editable within a Content Template.
Comments are always after the content, they do not belong to the content itself.
This is how WordPress coded it.
But with Layouts, and the Starter Theme, you can achieve your goal easily.
Hi Beda
Thanks for the suggestion but I don't want to use Layouts.
Can we go back to my previous questions (below) which were prompted by your guidance to create a Child Theme to remove that?
am I right in understanding you mean I need to add one of the theme files into my theme child folder and amend it as required? If so, could you clarify what I need to remove from which theme file to remove the second instance of comments please?
Many thanks
I cannot inform you where and what to remove or add exactly, as I do not know this Theme and cannot debug 3rd party Software according to the Support Guidelines.
https://toolset.com/toolset-support-policy/
A child theme in WordPress allows you to fully customize the Parent Theme.
You will create a Child theme, that needs some default files:
https://codex.wordpress.org/Child_Themes
Then, each file you take from the parent theme and put into this Child Theme (unless stated otherwise by your own theme), will be overwritten by the new Child theme File.
So, you need to find the comments template or code responsible for comments in your theme.
Normally this is called in the content template file with a function that is registered in another file (usually within a folder in the theme).
You will start where the theme outputs the content, usually single.php.
There you will see where the comments are loaded.
That file needs to go to the child theme and be modified accordingly.
I do not know this Theme and cannot debug 3rd party Software according to the Support Guidelines
You don't know the Toolset Start Theme???
Hi Julie,
Beda is not available today, I will replace him in this ticket.
I'm checking the issue right now and I will get back to you ASAP.
Thanks.
Hi Julie,
In Toolset starter theme, the code which is responsible for displaying the comments section is in /toolset-starter/single.php
At line 15
<?php comments_template(); ?>
I hope this can help you.
Thanks.
Hi Mohammed
Thank you so much for this; I could have spent months trawling through files looking for the code to remove!
🙂