In my last Blogging 101 post, I talked about displaying featured images for your WordPress RSS Feed. Today, I am sharing with you a very simple one-liner code fix for displaying next previous post links in WordPress.
But first, why do you need Next Previous Links?
- Next/Previous Links present another opportunity for you to capture the readers’ attention and make them stay longer on your site.
- It is one of the simplest ways to gain more page views from your readers with very minimal coding needed from your end. This is because WordPress provides inbuilt functions to retrieve the next/previous link information and you only have to worry about coding the “look and feel” aspect of the links.
So, here’s the simple code hack on how to do it for the PHP coding enthusiasts out there:
How to write one-liner code for next previous post links in WordPress?
Include the below code snippet in your single.php file at appropriate positions. My favorites include just above the article heading and just below it:
<div><h5><?php previous_post_link(‘%link’,’«« Previous: %title ‘); ?> | <?php next_post_link(‘%link’,’ %title :Next »»’) ?></h5></div>
In the above code snippet, a couple of things that you should customize based on your preferences are:
- Next/Previous Label => Change the label to your preferred nomenclature.
- « » => This is the ‘less than’ and ‘greater than’ signs before and after the labels. Change it as per your preference.
- %title => You can display the title or skip it, display the thumbnail with the title or any other choice.
- ‘|’ Delimiter => This is the delimiter between the next post and previous post links. You can change it as per your choice.
And there you have it!
A simple one-liner PHP code-fix to display next and previous post links.
Did you find this tip useful? How better to optimize it? Don’t forget to share your views in the comments section below.
PS: If you liked this WordPress Blogging 101 Tip, don’t forget to share it on your favorite social media platforms.