get_previous_posts_link()
Gets an HTML link (<a>) to the page with previous posts (newer posts).
Since posts in WordPress are displayed in reverse chronological order
Since posts are usually sorted in reverse chronological order (later posts are shown first), get_previous_posts_link() usually points to earlier posts. If you need to get a link to later posts (next), use the opposite function get_next_posts_link(), which points to past posts.
Hooks from the function
Returns
String|null. A link to a group of previous posts in pagination.
Usage
get_previous_posts_link( $label );
- $label(string)
- Text of the link.
Default: __( '« Previous Page' )
Examples
#1 Let's write the link to the previous posts into a variable and display it
$prev = get_previous_posts_link(); echo $prev;
#2 Removing Trailing Slashes from Prev & Next links
If you are using no-end-trailing slashes for your URLs. You may add following filter in your functions file to remove trailing slashes from generated links from get_previous_posts_links() function.
add_filter( 'get_pagenum_link', 'user_trailingslashit' );
Notes
- Global. Int.
$paged
Changelog
| Since 2.7.0 | Introduced. |