[Resolved] Move Comments section before the footer

Home Forums Support [Resolved] Move Comments section before the footer

Home Forums Support Move Comments section before the footer

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1661410
    Alejandro

    Hi,
    My blog section is organized in two columns (content + sidebar). At the end of the content column I have the comments section which I would like to move outside and place it before the footer (along with other elements such breadcrumbs, social share buttons, related posts, etc).

    Apart from the comments, I can move the rest of the items via Hook Element but I do not know how to deal with the comments.

    Could you provide some help here?

    Thank you

    #1661647
    David
    Staff
    Customer Support

    Hi there,

    currently it is baked into the single.php

    Tom explains what to do here:

    https://generatepress.com/forums/topic/move-comments-to-different-area/#post-1274565

    Then further down on the same topic how to hook the form back in:

    https://generatepress.com/forums/topic/move-comments-to-different-area/#post-1277317

    #1661896
    Alejandro

    Oh, wonderful!
    I am using a child theme so the only thing I have to do is to replicate the file with Tom’s indications on the child theme folder in my server right?
    thank you

    #1661947
    David
    Staff
    Customer Support

    Thats correct!

    #1662290
    Alejandro

    Mmmm, I was looking for the piece of code you mention (link) but does not look like my single.php file:

    <?php
    /**
     * The Template for displaying all single posts.
     *
     * @package GeneratePress
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.
    }
    
    get_header(); ?>
    
    	<div id="primary" <?php generate_do_element_classes( 'content' ); ?>>
    		<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
    			<?php
    			/**
    			 * generate_before_main_content hook.
    			 *
    			 * @since 0.1
    			 */
    			do_action( 'generate_before_main_content' );
    
    			if ( generate_has_default_loop() ) {
    				while ( have_posts() ) :
    
    					the_post();
    
    					generate_do_template_part( 'single' );
    
    				endwhile;
    			}
    
    			/**
    			 * generate_after_main_content hook.
    			 *
    			 * @since 0.1
    			 */
    			do_action( 'generate_after_main_content' );
    			?>
    		</main>
    	</div>
    
    	<?php
    	/**
    	 * generate_after_primary_content_area hook.
    	 *
    	 * @since 2.0
    	 */
    	do_action( 'generate_after_primary_content_area' );
    
    	generate_construct_sidebars();
    
    	get_footer();

    Could you tell me which part of the code I should get rid off?

    Thanks!

    #1663535
    Tom
    Lead Developer
    Lead Developer

    As of 3.0.0, it’s actually hooked into the template: https://github.com/tomusborne/generatepress/blob/3.0.2/inc/structure/comments.php#L177

    So we can move it like this:

    add_action( 'wp', function() {
        remove_action( 'generate_after_do_template_part', 'generate_do_comments_template', 15 );
    } );
    
    add_action( 'generate_before_footer', function() {
        if ( is_page() || is_single() ) {
            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;
        }
    } );
    #1663718
    Alejandro

    Thanks Tom.
    I’ve added this code to my functions.php file in my child theme and I can see the comments right before the footer.
    But I still don’t know how to get rid of the comments in their original position… Where (and which) lines I have to delete?

    Best, A.

    #1663730
    Tom
    Lead Developer
    Lead Developer

    That’s what this line should do:

    remove_action( 'generate_after_do_template_part', 'generate_do_comments_template', 15 );

    Can you confirm that it’s been added?

    #1663757
    Alejandro

    Yep, confirmed!

    #1664044
    Alejandro

    I mean, confirmed that has been added but is not working well as said before…

    #1664883
    Tom
    Lead Developer
    Lead Developer
    #1664889
    Alejandro

    Works flawlessly! Thanks Tom & David ๐Ÿ™‚

    #1664915
    Tom
    Lead Developer
    Lead Developer

    Glad we could help! ๐Ÿ™‚

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