: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$next_page = (int) $paged + 1;
if ( ! $max_page || $max_page >= $next_page ) {
return get_pagenum_link( $next_page );
* Displays or retrieves the next posts page link.
* @param int $max_page Optional. Max pages. Default 0.
* @param bool $display Optional. Whether to echo the link. Default true.
* @return string|void The link URL for next posts page if `$display = false`.
function next_posts( $max_page = 0, $display = true ) {
$link = get_next_posts_page_link( $max_page );
$output = $link ? esc_url( $link ) : '';
* Retrieves the next posts page link.
* @global WP_Query $wp_query WordPress Query object.
* @param string $label Content for link text.
* @param int $max_page Optional. Max pages. Default 0.
* @return string|void HTML-formatted next posts page link.
function get_next_posts_link( $label = null, $max_page = 0 ) {
global $paged, $wp_query;
$max_page = $wp_query->max_num_pages;
$next_page = (int) $paged + 1;
$label = __( 'Next Page »' );
if ( ! is_single() && ( $next_page <= $max_page ) ) {
* Filters the anchor tag attributes for the next posts page link.
* @param string $attributes Attributes for the anchor tag.
$attr = apply_filters( 'next_posts_link_attributes', '' );
'<a href="%1$s" %2$s>%3$s</a>',
next_posts( $max_page, false ),
preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label )
* Displays the next posts page link.
* @param string $label Content for link text.
* @param int $max_page Optional. Max pages. Default 0.
function next_posts_link( $label = null, $max_page = 0 ) {
echo get_next_posts_link( $label, $max_page );
* Retrieves the previous posts page link.
* Will only return string, if not on a single page or post.
* Backported to 2.0.10 from 2.1.3.
* @return string|void The link for the previous posts page.
function get_previous_posts_page_link() {
$previous_page = (int) $paged - 1;
if ( $previous_page < 1 ) {
return get_pagenum_link( $previous_page );
* Displays or retrieves the previous posts page link.
* @param bool $display Optional. Whether to echo the link. Default true.
* @return string|void The previous posts page link if `$display = false`.
function previous_posts( $display = true ) {
$output = esc_url( get_previous_posts_page_link() );
* Retrieves the previous posts page link.
* @param string $label Optional. Previous page link text.
* @return string|void HTML-formatted previous page link.
function get_previous_posts_link( $label = null ) {
$label = __( '« Previous Page' );
if ( ! is_single() && $paged > 1 ) {
* Filters the anchor tag attributes for the previous posts page link.
* @param string $attributes Attributes for the anchor tag.
$attr = apply_filters( 'previous_posts_link_attributes', '' );
'<a href="%1$s" %2$s>%3$s</a>',
preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label )
* Displays the previous posts page link.
* @param string $label Optional. Previous page link text.
function previous_posts_link( $label = null ) {
echo get_previous_posts_link( $label );
* Retrieves the post pages link navigation for previous and next pages.
* @global WP_Query $wp_query WordPress Query object.
* @param string|array $args {
* Optional. Arguments to build the post pages link navigation.
* @type string $sep Separator character. Default '—'.
* @type string $prelabel Link text to display for the previous page link.
* Default '« Previous Page'.
* @type string $nxtlabel Link text to display for the next page link.
* Default 'Next Page »'.
* @return string The posts link navigation.
function get_posts_nav_link( $args = array() ) {
'prelabel' => __( '« Previous Page' ),
'nxtlabel' => __( 'Next Page »' ),
$args = wp_parse_args( $args, $defaults );
$max_num_pages = $wp_query->max_num_pages;
$paged = get_query_var( 'paged' );
// Only have sep if there's both prev and next results.
if ( $paged < 2 || $paged >= $max_num_pages ) {
if ( $max_num_pages > 1 ) {
$return = get_previous_posts_link( $args['prelabel'] );
$return .= preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep'] );
$return .= get_next_posts_link( $args['nxtlabel'] );
* Displays the post pages link navigation for previous and next pages.
* @param string $sep Optional. Separator for posts navigation links. Default empty.
* @param string $prelabel Optional. Label for previous pages. Default empty.
* @param string $nxtlabel Optional Label for next pages. Default empty.
function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
$args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel' ) );
echo get_posts_nav_link( $args );
* Retrieves the navigation to next/previous post, when applicable.
* @since 4.4.0 Introduced the `in_same_term`, `excluded_terms`, and `taxonomy` arguments.
* @since 5.3.0 Added the `aria_label` parameter.
* @since 5.5.0 Added the `class` parameter.
* Optional. Default post navigation arguments. Default empty array.
* @type string $prev_text Anchor text to display in the previous post link.
* @type string $next_text Anchor text to display in the next post link.
* @type bool $in_same_term Whether link should be in the same taxonomy term.
* @type int[]|string $excluded_terms Array or comma-separated list of excluded term IDs.
* @type string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'.
* @type string $screen_reader_text Screen reader text for the nav element.
* Default 'Post navigation'.
* @type string $aria_label ARIA label text for the nav element. Default 'Posts'.
* @type string $class Custom class for the nav element. Default 'post-navigation'.
* @return string Markup for post links.
function get_the_post_navigation( $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'];
'taxonomy' => 'category',
'screen_reader_text' => __( 'Post navigation' ),
'aria_label' => __( 'Posts' ),
'class' => 'post-navigation',
$previous = get_previous_post_link(
'<div class="nav-previous">%link</div>',
$next = get_next_post_link(
'<div class="nav-next">%link</div>',
// Only add markup if there's somewhere to navigate to.
if ( $previous || $next ) {
$navigation = _navigation_markup( $previous . $next, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
* Displays the navigation to next/previous post, when applicable.
* @param array $args Optional. See get_the_post_navigation() for available arguments.
function the_post_navigation( $args = array() ) {
echo get_the_post_navigation( $args );
* Returns the navigation to next/previous set of posts, when applicable.
* @since 5.3.0 Added the `aria_label` parameter.
* @since 5.5.0 Added the `class` parameter.
* @global WP_Query $wp_query WordPress Query object.
* Optional. Default posts navigation arguments. Default empty array.
* @type string $prev_text Anchor text to display in the previous posts link.
* @type string $next_text Anchor text to display in the next posts link.
* @type string $screen_reader_text Screen reader text for the nav element.
* Default 'Posts navigation'.
* @type string $aria_label ARIA label text for the nav element. Default 'Posts'.
* @type string $class Custom class for the nav element. Default 'posts-navigation'.
* @return string Markup for posts links.
function get_the_posts_navigation( $args = array() ) {
// Don't print empty markup if there's only one page.
if ( $wp_query->max_num_pages > 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 posts' ),
'next_text' => __( 'Newer posts' ),
'screen_reader_text' => __( 'Posts navigation' ),
'aria_label' => __( 'Posts' ),
'class' => 'posts-navigation',
$next_link = get_previous_posts_link( $args['next_text'] );
$prev_link = get_next_posts_link( $args['prev_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 the navigation to next/previous set of posts, when applicable.
* @param array $args Optional. See get_the_posts_navigation() for available arguments.
function the_posts_navigation( $args = array() ) {
echo get_the_posts_navigation( $args );
* Retrieves a paginated navigation to next/previous set of posts, when applicable.
* @since 5.3.0 Added the `aria_label` parameter.
* @since 5.5.0 Added the `class` parameter.
* @global WP_Query $wp_query WordPress Query object.
* Optional. Default pagination arguments, see paginate_links().
* @type string $screen_reader_text Screen reader text for navigation element.
* Default 'Posts navigation'.
* @type string $aria_label ARIA label text for the nav element. Default 'Posts'.
* @type string $class Custom class for the nav element. Default 'pagination'.
* @return string Markup for pagination links.
function get_the_posts_pagination( $args = array() ) {
// Don't print empty markup if there's only one page.
if ( $wp_query->max_num_pages > 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' => _x( 'Previous', 'previous set of posts' ),
'next_text' => _x( 'Next', 'next set of posts' ),
'screen_reader_text' => __( 'Posts navigation' ),
'aria_label' => __( 'Posts' ),
* Filters the arguments for posts pagination links.
* Optional. Default pagination arguments, see paginate_links().
* @type string $screen_reader_text Screen reader text for navigation element.
* Default 'Posts navigation'.
* @type string $aria_label ARIA label text for the nav element. Default 'Posts'.
* @type string $class Custom class for the nav element. Default 'pagination'.
$args = apply_filters( 'the_posts_pagination_args', $args );
// Make sure we get a string back. Plain is the next best thing.
if ( isset( $args['type'] ) && 'array' === $args['type'] ) {
// Set up paginated links.
$links = paginate_links( $args );
$navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] );
* Displays a paginated navigation to next/previous set of posts, when applicable.
* @param array $args Optional. See get_the_posts_pagination() for available arguments.
function the_posts_pagination( $args = array() ) {
echo get_the_posts_pagination( $args );
* Wraps passed links in navigational markup.
* @since 5.3.0 Added the `aria_label` parameter.
* @param string $links Navigational links.
* @param string $css_class Optional. Custom class for the nav element.