Make WordPress Core

Opened 7 months ago

Last modified 4 months ago

#51189 new enhancement

comments_pagination_base missing in get_comment_reply_link() function

Reported by: MrPauloEn Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.5
Component: Comments Keywords: has-screenshots needs-patch needs-testing
Focuses: accessibility Cc:


Hi guys.

I noticed that get_comment_reply_link() does not create a valid reply link when comments are paginated.

When I say: "not valid" I mean without comments_pagination_base part like this is in previous_comments_link or next_comments_link or get_comment_link function.

I reffer exactly to this line:

This issue is hard to notice until javacsript is disabled or the comment-reply script is not loaded or works incorrectly.

Only then this link is an ordinary clickable link. If you click it, the page reloads as usually to show us such a reply form:


You reply to: Jane Doe:

Username is then linked to his comment. So when you click it, it should move you to this comment. It works correctly if you have only one comment page.


It won't work, if you split comments into pages.
Option: page_comments is enabled an there are more than one comment page.

It won't move you, if comment is on another page.


Because there is comments_pagination_base missing in that url.

Consider this with an example.

Now my comment reply link is this:


And the comment has this link:


If I want to jump for a moment to this comment, I can't. It just produce this link and nothing happens:


But when I slightly modify it:


So, the mentioned author anchor has this link:

And so, the comment has this link:

It skip to this comment when I clik user name anchor and come back when I click Reply link, becaouse username anchor has comment pagination url part.

So whan I did.

I looked into get_comment_reply_link() function, I copied some of a piece of code and I made a new filter, hooked to comment_reply_link filter.

I just added this to url in add_query_arg function:

get_permalink( $post->ID ) . $wp_rewrite->comments_pagination_base . '-' . $page . '/'

Whole filter looks like this:

add_filter( 'comment_reply_link', 'the_bootstrap_blog__filter_comment_reply_link', 10, 4 );
function the_bootstrap_blog__filter_comment_reply_link( $link, $args, $comment, $post ){
	global $wp_rewrite;

	$page = get_page_of_comment( $comment->comment_ID );

// Copied from get_comment_reply_link() function
	if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
		$link = sprintf(
			'<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
			esc_url( wp_login_url( get_permalink() ) ),
	} else {
		$data_attributes = array(
			'commentid'      => $comment->comment_ID,
			'postid'         => $post->ID,
			'belowelement'   => $args['add_below'] . '-' . $comment->comment_ID,
			'respondelement' => $args['respond_id'],
			'replyto'        => sprintf( $args['reply_to_text'], $comment->comment_author ),

		$data_attribute_string = '';

		foreach ( $data_attributes as $name => $value ) {
			$data_attribute_string .= " data-${name}=\"" . esc_attr( $value ) . '"';

		$data_attribute_string = trim( $data_attribute_string );

		$link = sprintf(
			"<a rel='nofollow' class='comment-reply-link' href='%s' %s aria-label='%s'>%s</a>",
						'replytocom'      => $comment->comment_ID,
						'unapproved'      => false,
						'moderation-hash' => false,
					get_permalink( $post->ID ) . $wp_rewrite->comments_pagination_base . '-' . $page . '/'
			) . '#' . $args['respond_id'],
			esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
	 return $args['before'] . $link . $args['after'];

And it works fine.

I know that this is only for my testing purposes, but if I have to put the theme in the WordPress repository, it should be more like in this (get_comment_link()) function.

I use:

  • WordPress v5.5

I noticed this issue a long time ago, but somehow I ignored it, didn't know how to fix it.

I tested this on default theme (twentytwenty), with all plugins deactivated and on my theme with all plugins activated. In each cases is the same.

Only when I add that filter, thoses links works fine.

Change History (3)

This ticket was mentioned in Slack in #accessibility by azhiyadev. View the logs.

7 months ago

This ticket was mentioned in Slack in #accessibility by afercia. View the logs.

7 months ago

This ticket was mentioned in Slack in #accessibility by ryokuhi. View the logs.

4 months ago

Note: See TracTickets for help on using tickets.