Using WordPress ‘get_next_posts_page_link()’ PHP function

The get_next_posts_page_link() WordPress PHP function retrieves the next posts page link.

Usage

get_next_posts_page_link( $max_page = 0 );

Parameters

  • $max_page (int) – Optional. Max pages. Default 0.

More information

See WordPress Developer Resources: get_next_posts_page_link()

Examples

Basic usage

Get the next posts page link with default settings.

// Get the next posts page link
$next_posts_link = get_next_posts_page_link();

// Display the next posts page link
echo '<a href="' . $next_posts_link . '">Next Posts</a>';

Set a maximum number of pages

Get the next posts page link with a maximum of 5 pages.

// Set the maximum number of pages
$max_pages = 5;

// Get the next posts page link
$next_posts_link = get_next_posts_page_link($max_pages);

// Display the next posts page link
echo '<a href="' . $next_posts_link . '">Next Posts</a>';

Only display the next posts page link if it exists.

// Get the next posts page link
$next_posts_link = get_next_posts_page_link();

// Check if the next posts page link exists
if ($next_posts_link) {
    // Display the next posts page link
    echo '<a href="' . $next_posts_link . '">Next Posts</a>';
}

Add a custom CSS class to the next posts page link.

// Get the next posts page link
$next_posts_link = get_next_posts_page_link();

// Display the next posts page link with a custom CSS class
echo '<a href="' . $next_posts_link . '" class="custom-next-posts-link">Next Posts</a>';

Customize the text displayed for the next posts page link.

// Get the next posts page link
$next_posts_link = get_next_posts_page_link();

// Display the next posts page link with custom text
echo '<a href="' . $next_posts_link . '">See More Posts</a>';