Using WordPress ‘get_posts_nav_link()’ PHP function

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

Usage

get_posts_nav_link( array( 'sep' => '—', 'prelabel' => '« Previous Page', 'nxtlabel' => 'Next Page »' ) );

Parameters

  • $args (string|array): Optional. Arguments to build the post pages link navigation.
    • sep (string): Separator character. Default ‘—’.
    • prelabel (string): Link text to display for the previous page link. Default ‘« Previous Page’.
    • nxtlabel (string): Link text to display for the next page link. Default ‘Next Page »’. Default: array().

More information

See WordPress Developer Resources: get_posts_nav_link()

Examples

Basic usage

Display the default previous and next page links.

echo get_posts_nav_link();

Custom separator

Change the separator character between the previous and next page links.

echo get_posts_nav_link( array( 'sep' => ' | ' ) );

Change the text displayed for the previous and next page links.

echo get_posts_nav_link( array( 'prelabel' => 'Prev', 'nxtlabel' => 'Next' ) );

Change the separator character and text displayed for the previous and next page links.

echo get_posts_nav_link( array( 'sep' => ' | ', 'prelabel' => 'Prev', 'nxtlabel' => 'Next' ) );

Using a wrapper element

Wrap the output in a div with a custom class.

echo '<div class="custom-navigation">' . get_posts_nav_link() . '</div>';