get_previous_comments_link( string $label =  ): string|void

In this article

Retrieves the link to the previous comments page.

Parameters

$labelstringoptional
Label for comments link text.

Default:''

Return

string|void HTML-formatted link for the previous page of comments.

Source

function get_previous_comments_link( $label = '' ) {
	if ( ! is_singular() ) {
		return;
	}

	$page = get_query_var( 'cpage' );

	if ( (int) $page <= 1 ) {
		return;
	}

	$previous_page = (int) $page - 1;

	if ( empty( $label ) ) {
		$label = __( '&laquo; Older Comments' );
	}

	/**
	 * Filters the anchor tag attributes for the previous comments page link.
	 *
	 * @since 2.7.0
	 *
	 * @param string $attributes Attributes for the anchor tag.
	 */
	$attr = apply_filters( 'previous_comments_link_attributes', '' );

	return sprintf(
		'<a href="%1$s" %2$s>%3$s</a>',
		esc_url( get_comments_pagenum_link( $previous_page ) ),
		$attr,
		preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label )
	);
}

Hooks

apply_filters( ‘previous_comments_link_attributes’, string $attributes )

Filters the anchor tag attributes for the previous comments page link.

Changelog

VersionDescription
2.7.1Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.