get_previous_comments_link() WordPress Function

The get_previous_comments_link() function returns the link to the previous set of comments, if there is one. This is useful for paginating through a large number of comments.

get_previous_comments_link( string $label = '' ) #

Retrieves the link to the previous comments page.


Parameters

$label

(string)(Optional) Label for comments link text.

Default value: ''


Top ↑

Return

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


Top ↑

Source

File: wp-includes/link-template.php

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

	$page = get_query_var( 'cpage' );

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

	$prevpage = (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.
	 */
	return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
}


Top ↑

Changelog

Changelog
VersionDescription
2.7.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More