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 (
Checkout the complete syntax:
get_previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' )
get_previous_post_link function parameters
$format: Printing format for all of printing text, Including the link and whats around it.
%linkis the actual link (
$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="http://site-url.com/post-url/" rel="previous">« Previous Post's Title</a>