WordPress next_post_link() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints a link

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().

WordPress
<?php
next_post_link( '%link &raquo;', '%title' );
CallWhat 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
WordPress
next_post_link( string $format = '%link &raquo;', string $link = '%title', bool $in_same_term = false, int[]|string $excluded_terms = '', string $taxonomy = 'category' ): void

Parameters

ParameterDescription
$formatstring. Text around the link. %link is replaced by the link. Default is %link &raquo;.
$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 ValueDescription
voidNothing 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.

Example 1 — Basic next link

Print a next link with the default format.

WordPress
<div class="post-nav">
  <?php next_post_link(); ?>
</div>

How It Works

  1. With no arguments, the format is %link &raquo;.
  2. The link text is the title of the next post.
  3. On the newest post, nothing is printed.

Example 2 — Use your own text

Change the text around the link and the link text.

WordPress
<?php next_post_link( '<div class="next">%link</div>', 'Next post &rarr;' ); ?>

How It Works

  1. %link in the first argument is replaced by the full link.
  2. The second argument is the clickable text.
  3. 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.

WordPress
<?php
next_post_link(
  '%link &raquo;',
  '%title',
  true
);

How It Works

  1. The third argument true means same category only.
  2. A newer post in another category is skipped.
  3. Use the fifth argument to choose a different taxonomy such as post_tag.

Frequently Asked Questions

It prints a link to the next single post, which is the post published after the current one.
next_post_link() moves between single posts. next_posts_link() moves between pages of an archive list.
Use the second argument, for example next_post_link( '%link', 'Next post' ).
Pass true as the third argument.
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

Mari Selvan M P
Mari Selvan M P ๐Ÿ”—

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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