: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Default 'posts-navigation'.
* @param string $screen_reader_text Optional. Screen reader text for the nav element.
* Default 'Posts navigation'.
* @param string $aria_label Optional. ARIA label for the nav element.
* Defaults to the value of `$screen_reader_text`.
* @return string Navigation template tag.
function _navigation_markup( $links, $css_class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) {
if ( empty( $screen_reader_text ) ) {
$screen_reader_text = /* translators: Hidden accessibility text. */ __( 'Posts navigation' );
if ( empty( $aria_label ) ) {
$aria_label = $screen_reader_text;
<nav class="navigation %1$s" aria-label="%4$s">
<h2 class="screen-reader-text">%2$s</h2>
<div class="nav-links">%3$s</div>
* Filters the navigation markup template.
* Note: The filtered template HTML must contain specifiers for the navigation
* class (%1$s), the screen-reader-text value (%2$s), placement of the navigation
* links (%3$s), and ARIA label text if screen-reader-text does not fit that (%4$s):
* <nav class="navigation %1$s" aria-label="%4$s">
* <h2 class="screen-reader-text">%2$s</h2>
* <div class="nav-links">%3$s</div>
* @param string $template The default template.
* @param string $css_class The class passed by the calling function.
* @return string Navigation template.
$template = apply_filters( 'navigation_markup_template', $template, $css_class );
return sprintf( $template, sanitize_html_class( $css_class ), esc_html( $screen_reader_text ), $links, esc_attr( $aria_label ) );
* Retrieves the comments page number link.
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
* @param int $pagenum Optional. Page number. Default 1.
* @param int $max_page Optional. The maximum number of comment pages. Default 0.
* @return string The comments page number link URL.
function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
$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' );
$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' );
$result = add_query_arg( 'cpage', $pagenum, $result );
* Filters the comments page number link for the current request.
* @param string $result The comments page number link.
return apply_filters( 'get_comments_pagenum_link', $result );
* Retrieves the link to the next comments page.
* @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 ) {
$page = get_query_var( 'cpage' );
$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 ) {
$label = __( 'Newer Comments »' );
* Filters the anchor tag attributes for the next comments page link.
* @param string $attributes Attributes for the anchor tag.
$attr = apply_filters( 'next_comments_link_attributes', '' );
'<a href="%1$s" %2$s>%3$s</a>',
esc_url( get_comments_pagenum_link( $next_page, $max_page ) ),
preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label )
* Displays the link to the next comments page.
* @param string $label Optional. Label for link text. Default empty.
* @param int $max_page Optional. Max page. Default 0.
function next_comments_link( $label = '', $max_page = 0 ) {
echo get_next_comments_link( $label, $max_page );
* Retrieves the link to the previous comments page.
* @param string $label Optional. Label for comments link text. Default empty.
* @return string|void HTML-formatted link for the previous page of comments.
function get_previous_comments_link( $label = '' ) {
$page = get_query_var( 'cpage' );
if ( (int) $page <= 1 ) {
$previous_page = (int) $page - 1;
$label = __( '« Older Comments' );
* Filters the anchor tag attributes for the previous comments page link.
* @param string $attributes Attributes for the anchor tag.
$attr = apply_filters( 'previous_comments_link_attributes', '' );
'<a href="%1$s" %2$s>%3$s</a>',
esc_url( get_comments_pagenum_link( $previous_page ) ),
preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label )
* Displays the link to the previous comments page.
* @param string $label Optional. Label for comments link text. Default empty.
function previous_comments_link( $label = '' ) {
echo get_previous_comments_link( $label );
* Displays or retrieves pagination links for the comments on the current post.
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
* @param string|array $args Optional args. See paginate_links(). Default empty array.
* @return void|string|array Void if 'echo' argument is true and 'type' is not an array,
* or if the query is not for an existing single post of any post type.
* Otherwise, markup for comment page links or array of comment page links,
* depending on 'type' argument.
function paginate_comments_links( $args = array() ) {
$page = get_query_var( 'cpage' );
$max_page = get_comment_pages_count();
'base' => add_query_arg( 'cpage', '%#%' ),
'add_fragment' => '#comments',
if ( $wp_rewrite->using_permalinks() ) {
$defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' );
$args = wp_parse_args( $args, $defaults );
$page_links = paginate_links( $args );
if ( $args['echo'] && 'array' !== $args['type'] ) {
* Retrieves navigation to next/previous set of comments, when applicable.
* @since 5.3.0 Added the `aria_label` parameter.
* @since 5.5.0 Added the `class` parameter.
* Optional. Default comments navigation arguments.
* @type string $prev_text Anchor text to display in the previous comments link.
* Default 'Older comments'.
* @type string $next_text Anchor text to display in the next comments link.
* Default 'Newer comments'.
* @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'.
* @type string $aria_label ARIA label text for the nav element. Default 'Comments'.
* @type string $class Custom class for the nav element. Default 'comment-navigation'.
* @return string Markup for comments links.
function get_the_comments_navigation( $args = array() ) {
// Are there comments to navigate through?
if ( get_comment_pages_count() > 1 ) {
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
$args['aria_label'] = $args['screen_reader_text'];
'prev_text' => __( 'Older comments' ),
'next_text' => __( 'Newer comments' ),
'screen_reader_text' => __( 'Comments navigation' ),
'aria_label' => __( 'Comments' ),
'class' => 'comment-navigation',
$prev_link = get_previous_comments_link( $args['prev_text'] );
$next_link = get_next_comments_link( $args['next_text'] );
$navigation .= '<div class="nav-previous">' . $prev_link . '</div>';
$navigation .= '<div class="nav-next">' . $next_link . '</div>';
$navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
* Displays navigation to next/previous set of comments, when applicable.
* @param array $args See get_the_comments_navigation() for available arguments. Default empty array.
function the_comments_navigation( $args = array() ) {
echo get_the_comments_navigation( $args );
* Retrieves a paginated navigation to next/previous set of comments, when applicable.
* @since 5.3.0 Added the `aria_label` parameter.
* @since 5.5.0 Added the `class` parameter.
* @see paginate_comments_links()
* Optional. Default pagination arguments.
* @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'.
* @type string $aria_label ARIA label text for the nav element. Default 'Comments'.
* @type string $class Custom class for the nav element. Default 'comments-pagination'.
* @return string Markup for pagination links.
function get_the_comments_pagination( $args = array() ) {
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) {
$args['aria_label'] = $args['screen_reader_text'];
'screen_reader_text' => __( 'Comments navigation' ),
'aria_label' => __( 'Comments' ),
'class' => 'comments-pagination',
// Make sure we get a string back. Plain is the next best thing.
if ( isset( $args['type'] ) && 'array' === $args['type'] ) {
$links = paginate_comments_links( $args );
$navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
* Displays a paginated navigation to next/previous set of comments, when applicable.
* @param array $args See get_the_comments_pagination() for available arguments. Default empty array.
function the_comments_pagination( $args = array() ) {
echo get_the_comments_pagination( $args );
* Retrieves the URL for the current site where the front end is accessible.
* Returns the 'home' option with the appropriate protocol. The protocol will be 'https'
* if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option.
* If `$scheme` is 'http' or 'https', is_ssl() is overridden.
* @param string $path Optional. Path relative to the home URL. Default empty.
* @param string|null $scheme Optional. Scheme to give the home URL context. Accepts
* 'http', 'https', 'relative', 'rest', or null. Default null.
* @return string Home URL link with optional path appended.
function home_url( $path = '', $scheme = null ) {
return get_home_url( null, $path, $scheme );
* Retrieves the URL for a given site where the front end is accessible.
* Returns the 'home' option with the appropriate protocol. The protocol will be 'https'
* if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option.
* If `$scheme` is 'http' or 'https', is_ssl() is overridden.
* @param int|null $blog_id Optional. Site ID. Default null (current site).
* @param string $path Optional. Path relative to the home URL. Default empty.
* @param string|null $scheme Optional. Scheme to give the home URL context. Accepts
* 'http', 'https', 'relative', 'rest', or null. Default null.
* @return string Home URL link with optional path appended.
function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
if ( empty( $blog_id ) || ! is_multisite() ) {
$url = get_option( 'home' );
switch_to_blog( $blog_id );
$url = get_option( 'home' );
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
$scheme = parse_url( $url, PHP_URL_SCHEME );
$url = set_url_scheme( $url, $scheme );
if ( $path && is_string( $path ) ) {
$url .= '/' . ltrim( $path, '/' );
* @param string $url The complete home URL including scheme and path.
* @param string $path Path relative to the home URL. Blank string if no path is specified.
* @param string|null $orig_scheme Scheme to give the home URL context. Accepts 'http', 'https',
* 'relative', 'rest', or null.
* @param int|null $blog_id Site ID, or null for the current site.
return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id );
* Retrieves the URL for the current site where WordPress application files
* (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
* Returns the 'site_url' option with the appropriate protocol, 'https' if
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
* @param string $path Optional. Path relative to the site URL. Default empty.
* @param string|null $scheme Optional. Scheme to give the site URL context. See set_url_scheme().
* @return string Site URL link with optional path appended.
function site_url( $path = '', $scheme = null ) {
return get_site_url( null, $path, $scheme );
* Retrieves the URL for a given site where WordPress application files
* (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
* Returns the 'site_url' option with the appropriate protocol, 'https' if
* is_ssl() and 'http' otherwise. If `$scheme` is 'http' or 'https',
* `is_ssl()` is overridden.
* @param int|null $blog_id Optional. Site ID. Default null (current site).
* @param string $path Optional. Path relative to the site URL. Default empty.
* @param string|null $scheme Optional. Scheme to give the site URL context. Accepts
* 'http', 'https', 'login', 'login_post', 'admin', or
* 'relative'. Default null.
* @return string Site URL link with optional path appended.