- This topic has 12 replies, 3 voices, and was last updated 3 years, 1 month ago by Tom.
-
AuthorPosts
-
February 17, 2021 at 2:13 am #1661410Alejandro
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
February 17, 2021 at 6:31 am #1661647DavidStaffCustomer SupportHi 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
February 17, 2021 at 7:30 am #1661896AlejandroOh, 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 youFebruary 17, 2021 at 8:00 am #1661947DavidStaffCustomer SupportThats correct!
February 17, 2021 at 12:27 pm #1662290AlejandroMmmm, 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!
February 18, 2021 at 9:59 am #1663535TomLead DeveloperLead DeveloperAs 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; } } );
February 18, 2021 at 1:19 pm #1663718AlejandroThanks Tom.
I’ve added this code to myfunctions.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.
February 18, 2021 at 1:43 pm #1663730TomLead DeveloperLead DeveloperThat’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?
February 18, 2021 at 2:30 pm #1663757AlejandroYep, confirmed!
February 19, 2021 at 12:15 am #1664044AlejandroI mean, confirmed that has been added but is not working well as said before…
February 19, 2021 at 10:49 am #1664883TomLead DeveloperLead DeveloperCan you try the updated code here?: https://generatepress.com/forums/topic/move-comments-section-before-the-footer/#post-1663535
February 19, 2021 at 10:53 am #1664889AlejandroWorks flawlessly! Thanks Tom & David ๐
February 19, 2021 at 11:22 am #1664915TomLead DeveloperLead DeveloperGlad we could help! ๐
-
AuthorPosts
- You must be logged in to reply to this topic.