How to get the Previous Post Link in WordPress

5 from 5
from 1 user
(Rate this post)
How to get the Previous Post Link in WordPress

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

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

Get the Previous Post Link in WordPress

You can try using 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.