WordPress previous_post_link() Function

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

Definition

In WordPress, previous_post_link() prints a link to the previous post. On a single post page it points to the post that was published right before the current one.

Use it with next_post_link() to let readers move between posts.

Syntax

A few ways to call previous_post_link().

WordPress
<?php
previous_post_link( '&laquo; %link', '%title' );
CallWhat it does
previous_post_link()Link with a « mark and the post title.
previous_post_link( '%link', 'Older post' )Link with your own text.
previous_post_link( '%link', '%title', true )Only posts in the same category.
previous_post_link( '%link', '%title', true, '5' )Same category, but skip category ID 5.

It prints the link. %link marks where the link goes, and %title in the link text is the post title.

Full declaration
WordPress
previous_post_link( string $format = '&laquo; %link', 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 &laquo; %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 ValueDescription
voidNothing is returned. The link is printed, or nothing if there is no previous post.

WordPress Examples

Three short examples. Each one shows the code and what it prints.

Example 1 — Basic previous link

Print a previous link with the default format.

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

How It Works

  1. With no arguments the format is &laquo; %link.
  2. The link text is the title of the previous post.
  3. On the oldest post nothing is printed.

Example 2 — Use your own text

Change the wrapper and the link text.

WordPress
<?php previous_post_link( '<div class="prev">%link</div>', '&larr; Previous post' ); ?>

How It Works

  1. %link in the first argument becomes the full link.
  2. The second argument is the clickable text.
  3. The wrapper div shows only when a link exists.

Example 3 — Previous and next together

Use both functions in one navigation block.

WordPress
<nav class="post-nav">
  <?php previous_post_link( '%link', '&laquo; %title' ); ?>
  <?php next_post_link( '%link', '%title &raquo;' ); ?>
</nav>

How It Works

  1. The previous post is the one published earlier.
  2. The next post is the one published later.
  3. Each link is hidden if there is no post in that direction.

Frequently Asked Questions

It prints a link to the previous single post, which is the post published before the current one.
previous_post_link() moves between single posts. previous_posts_link() moves between pages of a list.
Use the second argument, for example previous_post_link( '%link', 'Older post' ).
Pass true as the third argument.
You may be on the oldest post, so there is no previous 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.

10 people found this page helpful