posts_nav_link()WP 0.71

Displays the post pages link navigation for previous and next pages.

No Hooks.

Return

null. Nothing (null).

Usage

posts_nav_link( $sep, $prelabel, $nxtlabel );
$sep(string)
Separator for posts navigation links.
Default: ''
$prelabel(string)
Label for previous pages.
Default: ''
$nxtlabel(string)
Optional Label for next pages.
Default: ''

Examples

0

#1 HTML that the function outputs

<?php posts_nav_link( $sep, $prelabel, $nextlabel ); ?>

It will:

<a href="link">« Previous page</a> — <a href="link">Next page »</a>
0

#2 To center it (show it in the middle of the page) use this code:

<div style="text-align:center;">
	<?php posts_nav_link(' - ', 'Previous page', 'Next page'); ?>
</div>
0

#3 As anchors links can use pictures, such as this:

<?php
posts_nav_link(
	' ',
	'<img src="' . get_stylesheet_directory_uri() . '/images/prev.jpg" />',
	'<img src="' . get_stylesheet_directory_uri() . '/images/next.jpg" />'
);
?>
0

#4 An alternative to this function

In some cases it's better to use two functions: previous_posts_link() and next_posts_link():

<div class="navigation">
	<div class="alignleft"><?php previous_posts_link( '« Previous Entries' ); ?></div>
	<div class="alignright"><?php next_posts_link( 'Next Entries »', '' ); ?></div>
</div>

Changelog

Since 0.71 Introduced.

posts_nav_link() code WP 6.4.3

function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
	$args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel' ) );
	echo get_posts_nav_link( $args );
}