Archived topic
Move Comments to different area
9 replies · Started by Carson on May 7, 2020
How would I move the comments to a different area, for example in the before_footer area as the last element (In case you have several elements in that area). Thank for any help!
Hi there,
As of right now, you'd need to overwrite the single.php template in your child theme and remove this code: https://github.com/tomusborne/generatepress/blob/2.4.2/single.php#L28-L43
Then you'd need to add that code into a hook to add it to your desired area.
We'll be making this hook-able by default in the future :)
That sounds easy, this is the code I delete and place in an element?
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || '0' != get_comments_number() ) :
/**
* generate_before_comments_container hook.
*
* @since 2.1
*/
do_action( 'generate_before_comments_container' );
?>
<div class="comments-area">
<?php comments_template(); ?>
</div>
<?php
endif;
Hi there,
thats correct.
This doesn't work and also my footer is gone now.
I create a new single.php in the child theme folder, then copy the entire code Tom linked into it. Then I cut the line 28-43 out and place it in an element, correct?
Yes, you would copy the single.php file from the parent theme and add it to your child theme.
Now in that child theme file, you need to remove the block of code I highlighted above.
All that should do is remove the comments from your single posts.
Yes, that removes the comment section. However I can't just copy paste that code in an element to make comments show somewhere else. What do I have to paste in the element?
This would go into a Hook Element:
<?php
if ( comments_open() || '0' != get_comments_number() ) :
do_action( 'generate_before_comments_container' );
?>
<div class="comments-area">
<?php comments_template(); ?>
</div>
<?php
endif;
?>
This works perfectly, not sure what I did wrong earlier. Thank you!
You're welcome :)