Home WordPress Posts Functions next_post_link() WordPress next_post_link() Function Definition In WordPress, next_post_link() prints a link to the next post . On a single post page it points to the post that was published right after the current one.
Use it with previous_post_link() to let readers move from one post to the next.
Syntax A few ways to call next_post_link().
<?php
next_post_link( '%link »', '%title' ); Call What it does next_post_link()Link with the post title and a ยป mark. next_post_link( '%link', 'Newer post' )Link with your own text. next_post_link( '%link', '%title', true )Only posts in the same category. next_post_link( '%link', '%title', true, '5' )Same category, but skip category ID 5.
It prints the link. Use %link in the format as the place for the link and %title in the link text for the post title.
Full declaration next_post_link( string $format = '%link »', string $link = '%title', bool $in_same_term = false, int[]|string $excluded_terms = '', string $taxonomy = 'category' ): void Parameters Parameter Description $formatstring. Text around the link. %link is replaced by the link. Default is %link ». $linkstring. The link text. %title is replaced by the post title. Default is %title. $in_same_termbool. true limits links to posts in the same term. Default is false. $excluded_termsint[]|string. Term IDs to skip. Default is empty. $taxonomystring. The taxonomy to use when $in_same_term is true. Default is category.
Return Value Return Value Description void Nothing is returned. The link is printed, or nothing if there is no next post.
WordPress Examples Three short examples. Each one shows the code and what it prints.
1. Basic next link 2. Use your own text 3. Stay inside the same category Example 1 — Basic next link Print a next link with the default format.
<div class="post-nav">
<?php next_post_link(); ?>
</div> <div class="post-nav">
<a href="https://example.com/newer-post/" rel="next">Newer Post Title</a> »
</div> How It Works With no arguments, the format is %link ». The link text is the title of the next post. On the newest post, nothing is printed. Example 2 — Use your own text Change the text around the link and the link text.
<?php next_post_link( '<div class="next">%link</div>', 'Next post →' ); ?> <div class="next"><a href="https://example.com/newer-post/" rel="next">Next post →</a></div> How It Works %link in the first argument is replaced by the full link.The second argument is the clickable text. The wrapper div is only shown when a link exists. Example 3 — Stay inside the same category Only link to posts in the same category.
<?php
next_post_link(
'%link »',
'%title',
true
); <a href="https://example.com/news/newer-news-post/" rel="next">Newer News Post</a> » How It Works The third argument true means same category only. A newer post in another category is skipped. Use the fifth argument to choose a different taxonomy such as post_tag. Frequently Asked Questions What does next_post_link() do? It prints a link to the next single post, which is the post published after the current one.
What is the difference between next_post_link() and next_posts_link()? next_post_link() moves between single posts. next_posts_link() moves between pages of an archive list.
How do I change the link text? Use the second argument, for example next_post_link( '%link', 'Next post' ).
How do I link only within the same category? Pass true as the third argument.
Why is nothing printed? You may be on the newest post, so there is no next post.
Browse all post functions Open the functions index for simple guides with examples and FAQs.
Post Functions Index → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
13 people found this page helpful
Helpful Share Copy link Suggestion