[Resolved] Move Comments to different area

Home Forums Support [Resolved] Move Comments to different area

Home Forums Support Move Comments to different area

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1274057
    Carson

    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!

    #1274565
    Tom
    Lead Developer
    Lead Developer

    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 ๐Ÿ™‚

    #1275099
    Carson

    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;
    #1275202
    David
    Staff
    Customer Support

    Hi there,

    thats correct.

    #1275502
    Carson

    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?

    #1276033
    Tom
    Lead Developer
    Lead Developer

    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.

    #1277073
    Carson

    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?

    #1277317
    Tom
    Lead Developer
    Lead Developer

    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;
    ?>
    #1281708
    Carson

    This works perfectly, not sure what I did wrong earlier. Thank you!

    #1282760
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.