the_post_navigation()WP 4.1.0

Displays the HTML block of links to the next and previous posts. Uses on a single post page: is_singular().

This function combines next_post_link() and previous_post_link() into a single function. The function is created for convenience in order to insert a navigation block between adjacent articles (posts) in one line.

To get the HTML code for processing, use get_the_post_navigation()

Not to be confused with the_posts_navigation(), which displays links to the next/previous page of set of posts, for example on category page.

No Hooks.


null. Nothing (null). Displays HTML code.


<?php the_post_navigation( $args ); ?>

Array that can contain the following parameters:

  • $prev_text(string)
    Anchor text to display in the previous post link.
    Default: '%title'

  • $next_text(string)
    Anchor text to display in the next post link.
    Default: '%title'

  • $in_same_term(true/false)
    Whether link should be in a same taxonomy term.
    Default: false

  • $excluded_terms(array/string)
    Array or comma-separated list of excluded term IDs.
    Default: ''

  • $taxonomy(string)
    Taxonomy, if $in_same_term is true.
    Default: 'category'

  • $screen_reader_text(string)
    Screen reader text for nav element.
    Default: 'Post navigation'

Default: array()



#1 Navigation links between posts

Let's output links to the next and previous entries (posts) on a separate page of is_single() type.

// next/prev. post
the_post_navigation( array(
	'prev_text' => '<span class="meta-nav" aria-hidden="true">Backward</span> ' .
		'<span class="screen-reader-text">Previous entry</span> ' .
		'<span class="post-title">%title</span>',
	'next_text' => '<span class="meta-nav" aria-hidden="true">Further</span> ' .
		'<span class="screen-reader-text">Next entry</span> ' .
		'<span class="post-title">%title</span>',
) );

As a result, we get such HTML code:

<nav class="navigation post-navigation" role="navigation">
	<h2 class="screen-reader-text">Posts navigation</h2>
	<div class="nav-links">
		<div class="nav-previous">
			<a href="//" rel="prev">
				<span class="meta-nav" aria-hidden="true">Backward</span>
				<span class="screen-reader-text">Previous entry</span>
				<span class="post-title">Some Post Title</span>
		<div class="nav-next">
			<a href="//" rel="next">
				<span class="meta-nav" aria-hidden="true">Further</span>
				<span class="screen-reader-text">Next entry</span>
				<span class="post-title">Hello World!</span>


Since 4.1.0 Introduced.

the_post_navigation() code WP 6.5.3

function the_post_navigation( $args = array() ) {
	echo get_the_post_navigation( $args );