Using WordPress ‘posts_nav_link()’ PHP function

The posts_nav_link() WordPress PHP function displays the post pages link navigation for previous and next pages.


posts_nav_link( $sep, $prelabel, $nxtlabel );


  • $sep string (Optional): Separator for posts navigation links. Default: ”
  • $prelabel string (Optional): Label for previous pages. Default: ”
  • $nxtlabel string (Optional): Optional Label for next pages. Default: ”

More information

See WordPress Developer Resources: posts_nav_link


Using Images

In this example, we replace the text with custom images for previous and next page links.

posts_nav_link( ' ', '<img src="' . esc_attr( get_bloginfo( 'stylesheet_directory' ) . '/images/prev.jpg' ) . '" />', '<img src="' . esc_attr( get_bloginfo( 'stylesheet_directory' ) . '/images/next.jpg' ) . '" />' );

Default Usage

By default, the posts_nav_link() looks like this: « Previous Page — Next Page »


Displays previous and next page links (“previous page · next page”) centered on the page.

<div style="text-align:center;">
    posts_nav_link( ' · ', 'previous page', 'next page' );

You can change the text in each of the links and in the text in between the links. This example changes the default text for previous and next pages.

    posts_nav_link( ' or ', 'You can go back to the previous page', 'you can go forward to the next page' );

Kubrick Theme Format (Better Code)

The Kubrick theme format for posts navigation, could be formatted this way. This example uses previous_posts_link() and next_posts_link() functions instead.

<div class="navigation">
    <div class="alignleft">
        previous_posts_link( '&laquo; Previous Entries' );
    <div class="alignright">
        next_posts_link( 'Next Entries &raquo;', '' );