wppaste
WordPress

get_the_posts_navigation( array $args = array() ): string

Since
4.1.0, 5.3.0, 5.5.0
Source
wp-includes/link-template.php:2878
Returns the navigation to next/previous set of posts, when applicable.

Parameters

$argsarrayoptional
Default posts navigation arguments. Default empty array.Default: array()
  • $prev_textstringdefault: 'Older posts'

    Anchor text to display in the previous posts link.
  • $next_textstringdefault: 'Newer posts'

    Anchor text to display in the next posts link.
  • $screen_reader_textstringdefault: 'Posts navigation'

    Screen reader text for the nav element.
  • $aria_labelstringdefault: 'Posts'

    ARIA label text for the nav element.
  • $classstringdefault: 'posts-navigation'

    Custom class for the nav element.

Return

string
Markup for posts links.

Uses · 5

Used by · 1

Source

function get_the_posts_navigation( $args = array() ) {	global $wp_query; 	$navigation = ''; 	// 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'];		} 		$args = wp_parse_args(			$args,			array(				'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'] ); 		if ( $prev_link ) {			$navigation .= '<div class="nav-previous">' . $prev_link . '</div>';		} 		if ( $next_link ) {			$navigation .= '<div class="nav-next">' . $next_link . '</div>';		} 		$navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] );	} 	return $navigation;}

History

Introduced in 4.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.5.0
Added the class parameter.from the docblock
5.3.0
Added the aria_label parameter.from the docblock
4.1.0
Introduced.from the docblock

About 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.