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:3129
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
- Scaling
- Constant
- Instructions
- 8–55
- Plugin surface
- 1 hook
- Called by
- 4
Reads stored settings via get_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 57.
Third-party callbacks on 'next_comments_link_attributes' run inside this call, and their cost is not bounded by anything here.
4 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8–22 | is_singular() |
is_singular() && $page !== null && empty($max_page) && $max_page | 22–25 | is_singular(), get_comment_pages_count() |
is_singular() && $page === null && !empty($max_page) && $max_page | 23–26 | is_singular(), get_query_var() |
is_singular() && $page === null && empty($max_page) && $max_page | 26–29 | is_singular(), get_query_var(), get_comment_pages_count() |
is_singular() && $page !== null && !empty($max_page) && !$max_page && !empty($label) | 41–44 | is_singular(), apply_filters(), get_comments_pagenum_link(), esc_url(), sprintf() |
is_singular() && $page !== null && empty($max_page) && !$max_page && !empty($label) | 44–47 | is_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–48 | is_singular(), __(), apply_filters(), get_comments_pagenum_link(), esc_url(), sprintf() |
is_singular() && $page === null && !empty($max_page) && !$max_page && !empty($label) | 45–48 | is_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–51 | is_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–51 | is_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–52 | is_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–55 | is_singular(), get_query_var(), get_comment_pages_count(), __(), apply_filters(), get_comments_pagenum_link(), esc_url(), sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 57 | 8–55 | 7 | |
| 8.5 | 57 | 8–55 | 7 | |
| 8.4 | 57 | 8–55 | 7 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 60 | 8–58 | 7 | |
| 8.2 | 60 | 8–58 | 7 | |
| 8.1 | 60 | 8–58 | 7 | |
| 7.4 | 60 | 8–58 | 7 |
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:
- apply_filters( next_comments_link_attributes )filterline 3169 (+40 into the body)
Filters the anchor tag attributes for the next comments page link.
Uses · 7
- is_singular()Determines whether the query is for an existing single post of any post type (post, attachment, page, custom post types).
- get_query_var()Retrieves the value of a query variable in the WP_Query class.
- get_comment_pages_count()Calculates the total number of comment pages.
- __()Retrieves the translation of $text.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- esc_url()Checks and cleans a URL.
- get_comments_pagenum_link()Retrieves the comments page number link.
Used by · 4
- get_the_comments_navigation()Retrieves navigation to next/previous set of comments, when applicable.
- next_comments_link()Displays the link to the next comments page.
- render_block_core_comments_pagination_next()Renders the `core/comments-pagination-next` block on the server.
- twentyfifteen_comment_nav()Displays navigation to next/previous comments when applicable.
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 »' ); } /** * 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', '&$1', $label ) );}Changelog
Introduced in 2.7.1. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
string|void to string|null.verified against sourcepage parameter.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.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.