The get_the_posts_navigation() WordPress PHP function returns the navigation to the next/previous set of posts when applicable.
Usage
echo get_the_posts_navigation(array( 'prev_text' => 'Previous Page', 'next_text' => 'Next Page', ));
Parameters
$args
(array) – Optional. Default posts navigation arguments.prev_text
(string) – Anchor text to display in the previous posts link. Default ‘Older posts’.next_text
(string) – Anchor text to display in the next posts link. Default ‘Newer posts’.screen_reader_text
(string) – Screen reader text for the nav element. Default ‘Posts navigation’.aria_label
(string) – ARIA label text for the nav element. Default ‘Posts’.class
(string) – Custom class for the nav element. Default ‘posts-navigation’.
More information
See WordPress Developer Resources: get_the_posts_navigation()
Examples
Basic usage
Display the default posts navigation.
echo get_the_posts_navigation();
Custom previous and next texts
Change the anchor text for previous and next posts links.
echo get_the_posts_navigation(array( 'prev_text' => 'Previous Page', 'next_text' => 'Next Page', ));
Custom screen reader text and ARIA label
Provide custom text for screen readers and ARIA label.
echo get_the_posts_navigation(array( 'screen_reader_text' => 'Navigate through posts', 'aria_label' => 'Post Navigation', ));
Custom CSS class
Add a custom CSS class to the nav element.
echo get_the_posts_navigation(array( 'class' => 'my-custom-class', ));
Complete customization
Customize all available options for the posts navigation.
echo get_the_posts_navigation(array( 'prev_text' => 'Go Back', 'next_text' => 'Go Forward', 'screen_reader_text' => 'Browse Posts', 'aria_label' => 'Post Browsing', 'class' => 'custom-posts-navigation', ));