get_next_comments_link

The timeline below displays how wordpress function get_next_comments_link has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Retrieves the link to the next comments page.
 *
 * @since 2.7.1
 *
 * @global WP_Query $wp_query WordPress Query object.
 *
 * @param string $label    Optional. Label for link text. Default empty.
 * @param int    $max_page Optional. Max page. Default 0.
 * @return string|void HTML-formatted link for the next page of comments.
 */
function get_next_comments_link($label = '', $max_page = 0)
{
    global $wp_query;
    if (!is_singular()) {
        return;
    }
    $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', '&#038;$1', $label));
}

WordPress Version: 5.6

/**
 * Retrieves the link to the next comments page.
 *
 * @since 2.7.1
 *
 * @global WP_Query $wp_query WordPress Query object.
 *
 * @param string $label    Optional. Label for link text. Default empty.
 * @param int    $max_page Optional. Max page. Default 0.
 * @return string|void HTML-formatted link for the next page of comments.
 */
function get_next_comments_link($label = '', $max_page = 0)
{
    global $wp_query;
    if (!is_singular()) {
        return;
    }
    $page = get_query_var('cpage');
    if (!$page) {
        $page = 1;
    }
    $nextpage = (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 ($nextpage > $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.
     */
    return '<a href="' . esc_url(get_comments_pagenum_link($nextpage, $max_page)) . '" ' . apply_filters('next_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
}

WordPress Version: 5.3

/**
 * Retrieves the link to the next comments page.
 *
 * @since 2.7.1
 *
 * @global WP_Query $wp_query WordPress Query object.
 *
 * @param string $label    Optional. Label for link text. Default empty.
 * @param int    $max_page Optional. Max page. Default 0.
 * @return string|void HTML-formatted link for the next page of comments.
 */
function get_next_comments_link($label = '', $max_page = 0)
{
    global $wp_query;
    if (!is_singular()) {
        return;
    }
    $page = get_query_var('cpage');
    if (!$page) {
        $page = 1;
    }
    $nextpage = intval($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 ($nextpage > $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.
     */
    return '<a href="' . esc_url(get_comments_pagenum_link($nextpage, $max_page)) . '" ' . apply_filters('next_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
}

WordPress Version: 4.6

/**
 * Retrieves the link to the next comments page.
 *
 * @since 2.7.1
 *
 * @global WP_Query $wp_query
 *
 * @param string $label    Optional. Label for link text. Default empty.
 * @param int    $max_page Optional. Max page. Default 0.
 * @return string|void HTML-formatted link for the next page of comments.
 */
function get_next_comments_link($label = '', $max_page = 0)
{
    global $wp_query;
    if (!is_singular()) {
        return;
    }
    $page = get_query_var('cpage');
    if (!$page) {
        $page = 1;
    }
    $nextpage = intval($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 ($nextpage > $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.
     */
    return '<a href="' . esc_url(get_comments_pagenum_link($nextpage, $max_page)) . '" ' . apply_filters('next_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
}

WordPress Version: 4.4

/**
 * Return the link to next comments page.
 *
 * @since 2.7.1
 *
 * @global WP_Query $wp_query
 *
 * @param string $label    Optional. Label for link text.
 * @param int    $max_page Optional. Max page.
 * @return string|void HTML-formatted link for the next page of comments.
 */
function get_next_comments_link($label = '', $max_page = 0)
{
    global $wp_query;
    if (!is_singular()) {
        return;
    }
    $page = get_query_var('cpage');
    if (!$page) {
        $page = 1;
    }
    $nextpage = intval($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 ($nextpage > $max_page) {
        return;
    }
    if (empty($label)) {
        $label = __('Newer Comments &raquo;');
    }
    /**
     * Filter the anchor tag attributes for the next comments page link.
     *
     * @since 2.7.0
     *
     * @param string $attributes Attributes for the anchor tag.
     */
    return '<a href="' . esc_url(get_comments_pagenum_link($nextpage, $max_page)) . '" ' . apply_filters('next_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
}

WordPress Version: 4.3

/**
 * Return the link to next comments page.
 *
 * @since 2.7.1
 *
 * @global WP_Query $wp_query
 *
 * @param string $label    Optional. Label for link text.
 * @param int    $max_page Optional. Max page.
 * @return string|void HTML-formatted link for the next page of comments.
 */
function get_next_comments_link($label = '', $max_page = 0)
{
    global $wp_query;
    if (!is_singular() || !get_option('page_comments')) {
        return;
    }
    $page = get_query_var('cpage');
    if (!$page) {
        $page = 1;
    }
    $nextpage = intval($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 ($nextpage > $max_page) {
        return;
    }
    if (empty($label)) {
        $label = __('Newer Comments &raquo;');
    }
    /**
     * Filter the anchor tag attributes for the next comments page link.
     *
     * @since 2.7.0
     *
     * @param string $attributes Attributes for the anchor tag.
     */
    return '<a href="' . esc_url(get_comments_pagenum_link($nextpage, $max_page)) . '" ' . apply_filters('next_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
}

WordPress Version: 4.2

/**
 * Return the link to next comments page.
 *
 * @since 2.7.1
 *
 * @param string $label Optional. Label for link text.
 * @param int $max_page Optional. Max page.
 * @return string|null HTML-formatted link for the next page of comments.
 */
function get_next_comments_link($label = '', $max_page = 0)
{
    global $wp_query;
    if (!is_singular() || !get_option('page_comments')) {
        return;
    }
    $page = get_query_var('cpage');
    if (!$page) {
        $page = 1;
    }
    $nextpage = intval($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 ($nextpage > $max_page) {
        return;
    }
    if (empty($label)) {
        $label = __('Newer Comments &raquo;');
    }
    /**
     * Filter the anchor tag attributes for the next comments page link.
     *
     * @since 2.7.0
     *
     * @param string $attributes Attributes for the anchor tag.
     */
    return '<a href="' . esc_url(get_comments_pagenum_link($nextpage, $max_page)) . '" ' . apply_filters('next_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
}

WordPress Version: 4.1

/**
 * Return the link to next comments page.
 *
 * @since 2.7.1
 *
 * @param string $label Optional. Label for link text.
 * @param int $max_page Optional. Max page.
 * @return string|null HTML-formatted link for the next page of comments.
 */
function get_next_comments_link($label = '', $max_page = 0)
{
    global $wp_query;
    if (!is_singular() || !get_option('page_comments')) {
        return;
    }
    $page = get_query_var('cpage');
    $nextpage = intval($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 ($nextpage > $max_page) {
        return;
    }
    if (empty($label)) {
        $label = __('Newer Comments &raquo;');
    }
    /**
     * Filter the anchor tag attributes for the next comments page link.
     *
     * @since 2.7.0
     *
     * @param string $attributes Attributes for the anchor tag.
     */
    return '<a href="' . esc_url(get_comments_pagenum_link($nextpage, $max_page)) . '" ' . apply_filters('next_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
}

WordPress Version: 3.9

/**
 * Return the link to next comments page.
 *
 * @since 2.7.1
 *
 * @param string $label Optional. Label for link text.
 * @param int $max_page Optional. Max page.
 * @return string|null
 */
function get_next_comments_link($label = '', $max_page = 0)
{
    global $wp_query;
    if (!is_singular() || !get_option('page_comments')) {
        return;
    }
    $page = get_query_var('cpage');
    $nextpage = intval($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 ($nextpage > $max_page) {
        return;
    }
    if (empty($label)) {
        $label = __('Newer Comments &raquo;');
    }
    /**
     * Filter the anchor tag attributes for the next comments page link.
     *
     * @since 2.7.0
     *
     * @param string $attributes Attributes for the anchor tag.
     */
    return '<a href="' . esc_url(get_comments_pagenum_link($nextpage, $max_page)) . '" ' . apply_filters('next_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
}

WordPress Version: 3.7

/**
 * Return the link to next comments page.
 *
 * @since 2.7.1
 *
 * @param string $label Optional. Label for link text.
 * @param int $max_page Optional. Max page.
 * @return string|null
 */
function get_next_comments_link($label = '', $max_page = 0)
{
    global $wp_query;
    if (!is_singular() || !get_option('page_comments')) {
        return;
    }
    $page = get_query_var('cpage');
    $nextpage = intval($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 ($nextpage > $max_page) {
        return;
    }
    if (empty($label)) {
        $label = __('Newer Comments &raquo;');
    }
    return '<a href="' . esc_url(get_comments_pagenum_link($nextpage, $max_page)) . '" ' . apply_filters('next_comments_link_attributes', '') . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
}