Blogging 101

How to write one-liner code for next previous post links in WordPress

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.

wordpress

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’,’&laquo;&laquo; Previous: %title ‘); ?> | <?php next_post_link(‘%link’,’ %title :Next &raquo;&raquo;’) ?></h5></div>

Code Customizations

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.
  •  &laquo; &raquo; => 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.

next previous

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.

PIN THIS

Vote For Me @ The Top Mommy Blogs Directory Vote For Me @ The Top Mommy Blogs Directory
 

Leave A Comment

KEEP BROWSING

What brings you joy?

Four simple words. But enough to spiral my brain into a never-ending cycle of overthinking. What is joy? How is it different from happiness? What trig…