wppaste
WordPress

get_next_comments_link( string $label = '', int $max_page = 0, int|null $page = null ): string|void

Since
2.7.1, 6.7.0
Source
wp-includes/link-template.php:3121
Retrieves the link to the next comments page.

Compatibility

WordPress
since 6.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$labelstringoptional
Label for link text. Default empty.Default: ''
$max_pageintoptional
Max page. Default 0.Default: 0
$pageint|nulloptional
Page number. Default null.Default: null

Return value

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

Performance profile

How much work a call to get_next_comments_link() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Moderate

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
8–55

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 57.

Plugin surface
1 hook

Third-party callbacks on 'next_comments_link_attributes' run inside this call, and their cost is not bounded by anything here.

Called by
4

4 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()one call below get_next_comments_link()

Further down the call graph this can also reach cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 12 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_next_comments_link() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always8–22is_singular()
is_singular() && $page !== null && empty($max_page) && $max_page22–25is_singular(), get_comment_pages_count()
is_singular() && $page === null && !empty($max_page) && $max_page23–26is_singular(), get_query_var()
is_singular() && $page === null && empty($max_page) && $max_page26–29is_singular(), get_query_var(), get_comment_pages_count()
is_singular() && $page !== null && !empty($max_page) && !$max_page && !empty($label)41–44is_singular(), apply_filters(), get_comments_pagenum_link(), esc_url(), sprintf()
is_singular() && $page !== null && empty($max_page) && !$max_page && !empty($label)44–47is_singular(), get_comment_pages_count(), apply_filters(), get_comments_pagenum_link(), esc_url(), sprintf()
is_singular() && $page !== null && !empty($max_page) && !$max_page && empty($label)45–48is_singular(), __(), apply_filters(), get_comments_pagenum_link(), esc_url(), sprintf()
is_singular() && $page === null && !empty($max_page) && !$max_page && !empty($label)45–48is_singular(), get_query_var(), apply_filters(), get_comments_pagenum_link(), esc_url(), sprintf()
is_singular() && $page !== null && empty($max_page) && !$max_page && empty($label)48–51is_singular(), get_comment_pages_count(), __(), apply_filters(), get_comments_pagenum_link(), esc_url(), sprintf()
is_singular() && $page === null && empty($max_page) && !$max_page && !empty($label)48–51is_singular(), get_query_var(), get_comment_pages_count(), apply_filters(), get_comments_pagenum_link(), esc_url(), sprintf()
is_singular() && $page === null && !empty($max_page) && !$max_page && empty($label)49–52is_singular(), get_query_var(), __(), apply_filters(), get_comments_pagenum_link(), esc_url(), sprintf()
is_singular() && $page === null && empty($max_page) && !$max_page && empty($label)52–55is_singular(), get_query_var(), get_comment_pages_count(), __(), apply_filters(), get_comments_pagenum_link(), esc_url(), sprintf()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev578–557
8.5578–557
8.4578–5573 fewer instructions than PHP 8.3
8.3608–587
8.2608–587
8.1608–587
7.4608–587

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while get_next_comments_link() runs, in this order:

  1. apply_filters( next_comments_link_attributes )filterline 3161 (+40 into the body)

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

Uses · 7

Used by · 4

Source code

function get_next_comments_link( $label = '', $max_page = 0, $page = null ) {	global $wp_query; 	if ( ! is_singular() ) {		return;	} 	if ( is_null( $page ) ) {		$page = get_query_var( 'cpage' );	} 	if ( ! $page ) {		$page = 1;	} 	$next_page = (int) $page + 1; 	if ( empty( $max_page ) ) {		$max_page = $wp_query->max_num_comment_pages;	} 	if ( empty( $max_page ) ) {		$max_page = get_comment_pages_count();	} 	if ( $next_page > $max_page ) {		return;	} 	if ( empty( $label ) ) {		$label = __( 'Newer Comments &raquo;' );	} 	/**	 * Filters the anchor tag attributes for the next comments page link.	 *	 * @since 2.7.0	 *	 * @param string $attributes Attributes for the anchor tag.	 */	$attr = apply_filters( 'next_comments_link_attributes', '' ); 	return sprintf(		'<a href="%1$s" %2$s>%3$s</a>',		esc_url( get_comments_pagenum_link( $next_page, $max_page ) ),		$attr,		preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label )	);}

Changelog

Introduced in 2.7.1. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.0.4
Return type changed from string|void to string|null.verified against source
6.7.0
Added the page parameter.from the docblock
2.7.1
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.