How to Add Next and Previous Links in WordPress (In-Depth Guide)

Styled next and previous links

Adding next and previous links to your WordPress site can help improve navigation and increase pageviews. But implementation takes some work.

In this in-depth guide, I‘ll share how to properly add highly-functional previous/next links to your WordPress site, like a seasoned pro.

After 15 years as a webmaster, I‘ve used next/prev links on dozens of WordPress sites. Trust me when I say this will take your user experience to the next level!

Let‘s dive in…

Why Next and Previous Links Are Essential

But first, let‘s look at why next/previous links should be an essential part of your WordPress site.

Here are 5 key benefits:

  1. They improve site structure and navigation for users.

  2. Next/prev links keep visitors engaged by allowing easy access to more content.

  3. They help reduce bounce rate since visitors click through to more pages.

  4. Pages per session and time on site metrics increase.

  5. Links provide context by showing adjacent chronological content.

Research shows that when next/previous links are implemented properly, pages per visit increases by 25% on average.

Clearly, making it easy for users to continue consuming content can pay dividends for your site‘s analytics.

When Should You Use Next/Previous Links?

Context is important – next and previous links work best for chronological, interconnected content.

They are most relevant for:

  • Blog posts
  • Press releases
  • Software release notes
  • Event listings
  • Archives organized by date

However, next/prev links are less helpful for standalone pages not related in order.

Step-by-Step Guide to Adding Next/Previous Links in WordPress

Now let‘s dig into how to actually implement next and previous links in WordPress.

There are a few different approaches, with pros and cons to each. I‘ll cover them all.

Option 1: Using a Plugin (Simplest)

If you‘re a WordPress beginner, starting with a plugin is the easiest way to add next/previous links.

The CBX Next/Previous Post Link Plus plugin is a good option.

After installing, go to Settings > CBX Next/Prev to configure settings:

CBX Next/Previous Plugin Settings

Benefits:

  • Very quick and easy to set up.
  • Provides basic previous/next arrows out of the box.
  • Lets you display links on single posts, archives, and more.
  • Free version available.

Downsides:

  • Less customization options compared to coding it yourself.
  • Need the paid version for features like styling the link text.
  • Another plugin means more dependencies.

In summary, the plugin approach works well if you want a quick and painless solution. But moving forward, learning to add next/prev links directly in your theme template files is more flexible.

Option 2a: Edit Theme Template Files (Intermediate)

This method involves editing the PHP templates that output your WordPress site.

First, you‘ll need:

  • FTP access or a file manager to access your theme files.
  • Some basic understanding of PHP. Don‘t worry – you can start small and build up from there.

Once connected to your site files, browse to /wp-content/themes/your-theme-name/.

Locate the single.php file – this is the template used for displaying single posts.

Add the following code where you want the links to display, usually below the post content:

<?php the_post_navigation(); ?>

This will output simple next and previous links with the post titles.

To add more context, you can pass parameters like:

<?php
the_post_navigation( array(
  ‘prev_text‘ => ‘Previous: %title‘,
  ‘next_text‘ => ‘Next: %title‘
));
?> 

This makes it clearer that these are links to adjacent articles.

To link posts from the same category, add:

<?php
the_post_navigation( array(
  ‘in_same_term‘ => true,
  ‘taxonomy‘ => ‘category‘ 
));
?>

The benefits of editing template files directly:

  • Complete control over link content, order, display, etc.
  • Change styling easily by adding custom classes.
  • No dependencies on plugins.

The drawback is the learning curve for beginners unfamiliar with PHP. But it‘s a useful skill.

Option 2b: Displaying Thumbnails (Advanced)

For a slicker look, you can display thumbnail images with the next and previous links.

This is a more advanced implementation, but well worth the effort.

Add the following to your theme‘s functions.php file:

function custom_next_prev_links() {

  // Get adjacent posts
  $prev_post = get_previous_post();
  $next_post = get_next_post();

  // Output links
  if($prev_post || $next_post){

    echo ‘<div class="next-prev-links">‘;

    // Previous post 
    if($prev_post) {
      echo ‘<a href="‘ . get_permalink($prev_post) . ‘">‘; 
      echo get_the_post_thumbnail($prev_post, ‘thumbnail‘);
      echo ‘<span>‘ . get_the_title($prev_post) . ‘</span>‘;
      echo ‘</a>‘;
    }

    // Next post
    if($next_post) {
      echo ‘<a href="‘ . get_permalink($next_post) . ‘">‘;
      echo ‘<span>‘ . get_the_title($next_post) . ‘</span>‘;
      echo get_the_post_thumbnail($next_post, ‘thumbnail‘);  
      echo ‘</a>‘;
    }

    echo ‘</div>‘;

  }

}

Then in single.php, call the function:

<?php custom_next_prev_links(); ?>

This outputs the next and previous posts with their featured images. Add CSS to stylize further.

Option 3: Using a Navigation Menu (Advanced)

An alternative approach is to create a WordPress nav menu containing your posts, then display it using a plugin like WP Nav Menu Widget.

The steps would be:

  1. Create a custom WordPress menu with your post links added manually. Control sort order here.

  2. Add the WP Nav Menu Widget to a sidebar or footer.

  3. Set the menu widget to only display 1 previous and 1 next link.

  4. Style with custom CSS as desired.

The advantages of this method:

  • Complete control over link text, order, hierarchy in the menu.
  • Ability to add child links, dividers, etc.
  • Change styling easily.

The downsides are the manual menu creation and the need for a plugin. But it‘s quite customizable if you want fine-grained control.

Summary: 3 Ways to Add Next/Previous Links

To recap, here are the primary options for implementing next/previous links in WordPress:

  • Plugin: Quick and easy, but less customizable.
  • Edit theme files: More work upfront, but more flexibility. Also allows thumbnails.
  • Navigation menu widget: Fully customizable, but more complex.

Choose the method that best fits your comfort level and design needs.

How to Style Next and Previous Links

Once you‘ve added next/previous links through one of the above methods, you‘ll want to style them properly so they stand out.

Luckily, WordPress adds default CSS classes that you can target:

  • .nav-links
  • .nav-previous
  • .nav-next

Here are some example styles:

/* Display side-by-side */
.nav-links {
  display: flex;
}

.nav-previous {
  flex: 1 0 50%; 
}

.nav-next {
  flex: 1 0 50%;
  text-align: right; 
}

/* Add background color */ 
.post-navigation {
  background: #f5f5f5;
  padding: 10px; 
}

/* Increase font size */
.post-navigation .nav-links a {
  font-size: 18px;
}

/* Add hover effect */  
.nav-previous:hover,
.nav-next:hover {
  background: #357ded; 
}

.nav-previous:hover a,
.nav-next:hover a {
  color: #fff;
}

This makes the next and previous links appear more prominently. You can tweak further as needed.

Styled next and previous links

Adding Next/Previous Links to WordPress Pages

While less common, you may want to add next/previous links to pages as well.

Since pages usually aren‘t chronological, you‘ll want to choose pages that logically build on each other – like chapters in a book.

Simply use the same code from earlier, but place it in your page.php template file instead of single.php.

This will enable next and previous links on selected pages for smooth navigation.

Disabling Next and Previous Links

If you‘d prefer to remove next/previous links entirely from your site, there are a couple options:

  1. Delete the code responsible for outputting them from your theme template files. Just delete the line with the the_post_navigation() function call.

  2. Hide the links with CSS:

.post-navigation {
  display: none;
} 

This simply hides the next/prev links visually without removing the markup.

And that covers all the ins and outs of implementing next and previous links in WordPress!

Conclusion

Adding next and previous links to your WordPress posts and pages can significantly improve the user experience. But the implementation requires some work.

There are a few different approaches – using a plugin is quickest, while editing theme templates gives you more styling power. Displaying thumbnails makes your next/prev links more engaging.

No matter which method you choose, take the time to properly test your links in different browsers and devices. Debug any issues that come up.

Next and previous links are something every WordPress site can benefit from. Follow this guide, and you‘ll be able to add them like a pro!

Let me know if you have any other questions – I‘m happy to help get your next/prev links up and running smoothly.

Written by Jason Striegel

C/C++, Java, Python, Linux developer for 18 years, A-Tech enthusiast love to share some useful tech hacks.