Title: get_comments_pagenum_link
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_comments_pagenum_link( int $pagenum = 1, int $max_page ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#wp--skip-link--target)

Retrieves the comments page number link.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#parameters)󠁿

 `$pagenum`intoptional

Page number.

Default:`1`

`$max_page`intoptional

The maximum number of comment pages. Default 0.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#return)󠁿

 string The comments page number link URL.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#source)󠁿

    ```php
    function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
    	global $wp_rewrite;

    	$pagenum  = (int) $pagenum;
    	$max_page = (int) $max_page;

    	$result = get_permalink();

    	if ( 'newest' === get_option( 'default_comments_page' ) ) {
    		if ( $pagenum !== $max_page ) {
    			if ( $wp_rewrite->using_permalinks() ) {
    				$result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
    			} else {
    				$result = add_query_arg( 'cpage', $pagenum, $result );
    			}
    		}
    	} elseif ( $pagenum > 1 ) {
    		if ( $wp_rewrite->using_permalinks() ) {
    			$result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
    		} else {
    			$result = add_query_arg( 'cpage', $pagenum, $result );
    		}
    	}

    	$result .= '#comments';

    	/**
    	 * Filters the comments page number link for the current request.
    	 *
    	 * @since 2.7.0
    	 *
    	 * @param string $result The comments page number link.
    	 */
    	return apply_filters( 'get_comments_pagenum_link', $result );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/link-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/link-template.php#L3080)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/link-template.php#L3080-L3114)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#hooks)󠁿

 [apply_filters( ‘get_comments_pagenum_link’, string $result )](https://developer.wordpress.org/reference/hooks/get_comments_pagenum_link/)

Filters the comments page number link for the current request.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#related)󠁿

| Uses | Description | 
| [user_trailingslashit()](https://developer.wordpress.org/reference/functions/user_trailingslashit/)`wp-includes/link-template.php` |

Retrieves a trailing-slashed string if the site is set for adding trailing slashes.

  | 
| [WP_Rewrite::using_permalinks()](https://developer.wordpress.org/reference/classes/wp_rewrite/using_permalinks/)`wp-includes/class-wp-rewrite.php` |

Determines whether permalinks are being used.

  | 
| [trailingslashit()](https://developer.wordpress.org/reference/functions/trailingslashit/)`wp-includes/formatting.php` |

Appends a trailing slash.

  | 
| [add_query_arg()](https://developer.wordpress.org/reference/functions/add_query_arg/)`wp-includes/functions.php` |

Retrieves a modified URL query string.

  | 
| [get_permalink()](https://developer.wordpress.org/reference/functions/get_permalink/)`wp-includes/link-template.php` |

Retrieves the full permalink for the current post or post ID.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

[Show 5 more](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#)

| Used by | Description | 
| [wp_get_canonical_url()](https://developer.wordpress.org/reference/functions/wp_get_canonical_url/)`wp-includes/link-template.php` |

Returns the canonical URL for a post.

  | 
| [get_next_comments_link()](https://developer.wordpress.org/reference/functions/get_next_comments_link/)`wp-includes/link-template.php` |

Retrieves the link to the next comments page.

  | 
| [get_previous_comments_link()](https://developer.wordpress.org/reference/functions/get_previous_comments_link/)`wp-includes/link-template.php` |

Retrieves the link to the previous comments page.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_comments_pagenum_link/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comments_pagenum_link%2F)
before being able to contribute a note or feedback.