How to get the Previous Post Link in WordPress

5 from 5
from 1 user
(Rate this post)

Presenting Previous Post Link for visitors can generate more page views and increase conversion rate. WordPress introduced the get_previous_post_link function to help developers print the Previous Post Link easily and fast.

If a user is reading a post, the get_previous_post_link function can help the visitor navigate better through your website.

Like the get_next_post_link function (print the next post link), the get_previous_post_link function looks for the queried post by WordPress to generate a link for you.

get_previous_post_link Function Syntax

All of the parameters in get_previous_post_link function are optional!

It means that you can use this function just with parentheses (get_previous_post_link()).

Checkout the complete syntax:

    $format = '« %link',
    $link = '%title',
    $in_same_term = false,
    $excluded_terms = '',
    $taxonomy = 'category'

Explaining get_previous_post_link function parameters

  • $format: Printing format for all of printing text, Including the link and whats around it. %link is the actual link (<a> tag).
  • $link: Actual link printing format (<a> tag). Default value is ‘%title’.
  • $in_same_term: Specifies that you only need links from same taxonomy as the current post. Default value is false.
  • $excluded_terms: Excludes terms by Id. You can use comma-separated list of IDs or an array.
  • $taxonomy: Specifies what taxonomy you want to check for printing the previous post (category, tag, and etc).

Get the Previous Post Link in WordPress

You can try using the WordPress get_previous_post_link in the single.php of your currently active theme:



<a href="" rel="previous">« Previous Post's Title</a>

What do you think about "How to get the Previous Post Link in WordPress"?

Your rating submit was successfull.

Your rating submit was not successfull.