How to get the Previous Post Link in WordPress?

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.

5 from 5
from 1 user
(Rate this post)

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:

get_previous_post_link(
    $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:

get_previous_post_link();

Output:

<a href="http://site-url.com/post-url/" 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.

Menu