Move "leave comment" link using child theme

Hello,

I’d like to separate the “Leave a comment” link from the rest of the post meta, which I currently have at the top of the post, and put it at the bottom of the post when displayed in archives and on the front page.

If it’s easier, I can have the “Leave a comment” link appear both at the top and the bottom.

I’m using the unmodified child theme downloaded from this site.

Thanks for your help.

Hello Knepveu,

As per your query, you want to separate “Leave a comment” from post meta. Show “Leave a comment” in the top and bottom of post on blog post listing (home or archieve page).

Let me know if this is what you needed.

Copy the following code in your functions.php file and check the output.

// Remove Default Post Meta  
remove_action( 'rtp_hook_post_meta_top', 'rtp_default_post_meta' ); // Remove Post Meta Top  
remove_action( 'rtp_hook_post_meta_bottom', 'rtp_default_post_meta' ); // Remove Post Meta Bottom  

function rtp_custom_post_meta( $placement = 'top' ) {  

	if ( 'post' == get_post_type() && ! rtp_is_bbPress() ) {  
		global $post, $rtp_post_comments;  
		$position = ( 'bottom' == $placement ) ? 'l' : 'u'; // l = Lower/Bottom , u = Upper/Top  

		if ( rtp_has_postmeta( $position ) ) {  
			if ( $position == 'l' ) {  
				echo '';  
			} ?>  

			
<?php if ( 'bottom' == $placement ){ rtp_hook_begin_post_meta_bottom(); } else { rtp_hook_begin_post_meta_top(); } // Author Link if ( $rtp_post_comments[ 'post_author_' . $position ] || $rtp_post_comments[ 'post_date_' . $position ] ) { if ( $rtp_post_comments[ 'post_author_' . $position ] ) { printf( __( 'By %s', 'rtPanel' ), ( ! $rtp_post_comments[ 'author_link_' . $position ] ? get_the_author() . ( $rtp_post_comments[ 'author_count_' . $position ] ? '(' . get_the_author_posts() . ')' : '' ) : sprintf( __( '%3$s', 'rtPanel' ), get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ), esc_attr( sprintf( __( 'Posts by %s', 'rtPanel' ), get_the_author() ) ), get_the_author() ) . ( $rtp_post_comments[ 'author_count_' . $position ] ? '(' . get_the_author_posts() . ')' : '' ) ) ); } echo ( $rtp_post_comments[ 'post_author_' . $position ] && $rtp_post_comments[ 'post_date_' . $position ] ) ? ' ' : ''; if ( $rtp_post_comments[ 'post_date_' . $position ] ) { printf( __( '· %s', 'rtPanel' ), get_the_date( 'c' ), get_the_time( $rtp_post_comments[ 'post_date_format_' . $position ] ) ); } } // Post Categories echo ( get_the_category_list() && $rtp_post_comments[ 'post_category_' . $position ] ) ? ' · ' . get_the_category_list( ', ' ) . '' : ''; // Post Tags echo ( get_the_tag_list() && $rtp_post_comments[ 'post_tags_' . $position ] ) ? '

' . get_the_tag_list( __( 'Tagged', 'rtPanel' ) . ': ', ', ', '' ) . '

' : ''; // Post Custom Taxonomies $args = array( '_builtin' => false ); $taxonomies = get_taxonomies( $args, 'objects' ); foreach ( $taxonomies as $key => $taxonomy ) { ( get_the_terms( $post->ID, $key ) && isset( $rtp_post_comments[ 'post_' . $key . '_' . $position ] ) && $rtp_post_comments[ 'post_' . $key . '_' . $position ] ) ? the_terms( $post->ID, $key, '' . $taxonomy->labels->singular_name . ': ', ', ', '' ) : ''; } if ( 'bottom' == $placement ) rtp_hook_end_post_meta_bottom(); else rtp_hook_end_post_meta_top(); ?>
<?php if ( $position == 'l' ) { echo ''; } } } elseif ( ! rtp_is_bbPress() ) { if ( get_edit_post_link() && ( 'top' == $placement ) ) { ?>
<?php rtp_hook_end_post_meta_top(); ?>
<?php } } } // Add new custom post meta add_action( 'rtp_hook_post_meta_top', 'rtp_custom_post_meta' ); // Post Meta Top add_action( 'rtp_hook_post_meta_bottom', 'rtp_custom_post_meta' ); // Post Meta Bottom // Get comment count function rtp_custom_comment_count() { global $rtp_post_comments; add_filter( 'get_comments_number', 'rtp_only_comment_count', 11, 2 ); if ( ( is_archive() || is_home() || is_front_page() ) && ( ( ( get_comments_number() || @comments_open() ) && ! is_attachment() && ! rtp_is_bbPress() ) ) ) { // If post meta is set to top then only display the comment count. ?> <?php comments_popup_link( _x( 'Leave a comment', 'comments number', 'rtPanel' ), _x( '1 Comment', 'comments number', 'rtPanel' ), _x( '% Comments', 'comments number', 'rtPanel' ), 'rtp-post-comment rtp-common-link' ); ?><?php } remove_filter( 'get_comments_number', 'rtp_only_comment_count', 11, 2 ); } add_action( 'rtp_hook_post_meta_top', 'rtp_custom_comment_count' ); add_action( 'rtp_hook_post_meta_bottom', 'rtp_custom_comment_count' );

Hi, thanks for your help. Unfortunately I was unclear, so this is not quite what I was after.

  1. I only want the “leave a comment” to appear at the bottom, not BOTH the bottom and the top.

  2. Should this kind of change go into the child theme, and not the parent theme? If it should go in the child theme, what kind of changes in the code are necessary?

Thanks for your help. I appreciate it very much.

As you want to show “Leave a Comment” only on bottom then please remove following line from above provided code,
add_action( ‘rtp_hook_post_meta_top’, ‘rtp_custom_comment_count’ );

We used Child theme to customize parent theme functions without touching parent theme files. You can use direct parent theme, but will suggest use child for this kind of small changes.

Let me know if you have any other questions.

Thank you–that worked, but I also had to uncomment the relevant “remove” actions in rtp-custom-hooks-applied.php .

Glad to know your issue is resolved now.

Hi. I am also having a ‘Leave a comment’ issue. I am using the Disqus plugin for comments instead of the theme comment system.

Below the title of each post there is a link ‘Leave a comment’ which on clicking should redirect the reader to the disqus comments at the end of the post. But nothing happens on clicking the link. I believe the URL of the blog post URL is appended by ‘#respond’ on clicking but it really should be appending ‘#disqus_thread’.

Any suggestions how this can be fixed? The ‘Leave a comment’ links on the summary page of all posts is working fine.

My blog: http://scanova.io/blog

Hello Admin4,

To change link from “#respond” to “#disqus_thread”, you will need to overwrite comments.php file in child theme and replace the “#respond” to “#disqus_thread” on line no 34.

If you are using direct rtPanel theme then replace “#respond” to “#disqus_thread” in comments.php file.

Let us know if this can work for you.

Thanks,
Manish