Using WordPress ‘previous_posts_link()’ PHP function

The previous_posts_link() WordPress PHP function displays the link to the previous posts page.

Usage

previous_posts_link('Newer Posts');

Parameters

  • $label (string) – Optional. The text to display for the previous page link. Default: null.

More information

See WordPress Developer Resources: previous_posts_link

Examples

This example will display the default link text “« Newer Entries” for the previous posts page.

previous_posts_link( __( '« Newer Entries', 'textdomain' ) );

This example displays “Newer Posts” as the link text for the previous posts page.

previous_posts_link('Newer Posts');

This example shows how to add a custom CSS class to the previous posts link.

previous_posts_link('<span class="custom-prev-link">Newer Posts</span>');

This example checks if there is a previous posts page before displaying the link.

if (get_previous_posts_link()) {
    previous_posts_link('Newer Posts');
}

This example shows how to display both the previous and next posts links together.

previous_posts_link('Newer Posts');
next_posts_link('Older Posts', $the_query->max_num_pages);