Home WordPress Posts Functions previous_post_link() WordPress previous_post_link() Function 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().
<?php
previous_post_link( '« %link', '%title' ); Call What 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 previous_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 previous post.
WordPress Examples Three short examples. Each one shows the code and what it prints.
1. Basic previous link 2. Use your own text 3. Previous and next together Example 1 — Basic previous link Print a previous link with the default format.
<div class="post-nav">
<?php previous_post_link(); ?>
</div> <div class="post-nav">
« <a href="https://example.com/older-post/" rel="prev">Older Post Title</a>
</div> How It Works With no arguments the format is « %link. The link text is the title of the previous post. On the oldest post nothing is printed. Example 2 — Use your own text Change the wrapper and the link text.
<?php previous_post_link( '<div class="prev">%link</div>', '← Previous post' ); ?> <div class="prev"><a href="https://example.com/older-post/" rel="prev">← Previous post</a></div> How It Works %link in the first argument becomes the full link.The second argument is the clickable text. The wrapper div shows only when a link exists. Example 3 — Previous and next together Use both functions in one navigation block.
<nav class="post-nav">
<?php previous_post_link( '%link', '« %title' ); ?>
<?php next_post_link( '%link', '%title »' ); ?>
</nav> <nav class="post-nav">
<a href="https://example.com/older-post/" rel="prev">« Older Post</a>
<a href="https://example.com/newer-post/" rel="next">Newer Post »</a>
</nav> How It Works The previous post is the one published earlier. The next post is the one published later. Each link is hidden if there is no post in that direction. Frequently Asked Questions What does previous_post_link() do? It prints a link to the previous single post, which is the post published before the current one.
What is the difference between previous_post_link() and previous_posts_link()? previous_post_link() moves between single posts. previous_posts_link() moves between pages of a list.
How do I change the link text? Use the second argument, for example previous_post_link( '%link', 'Older post' ).
How do I stay in the same category? Pass true as the third argument.
Why is nothing printed? 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 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.
10 people found this page helpful
Helpful Share Copy link Suggestion