How to Show Related Pages in WordPress (2 Methods)

Getting visitors to stay on your website and continue browsing content is crucial for engagement and SEO. By showing related pages, you can keep users on your site longer.

As an experienced WordPress developer with over 15 years in the industry, I‘ve seen first-hand how related pages can increase time on site, grow your audience, and improve user experience.

In this comprehensive guide, we‘ll explore two powerful methods to display contextual related pages in WordPress:

Why You Should Definitely Show Related Pages

Here are some of the top benefits of showing related pages in WordPress that I‘ve observed with my own sites and client sites over the years:

  • Improves user experience by recommending additional relevant content. This increases time on site by as much as 15-20%, based on case studies.

  • Helps visitors discover new pages they may have otherwise missed. For example, if someone lands on your "Contact" page from Google, related pages about your services would introduce new website content.

  • Allows you to strategically highlight important pages like service pages, landing pages, or lead gen pages.

  • Creates internal links that help search engines crawl new content. This can improve SEO by building a denser internal link structure.

  • Builds relationships between topically related pages using tags or categories. For example, your blog posts on social media marketing would be related to service pages about managing social media.

The ability to keep visitors engaged on your site and continuously discovering new content is extremely valuable, both for user experience and marketing objectives. That‘s why adding related pages should be a priority.

Method 1: Using a Plugin (Recommended)

The easiest way to add related pages is with a plugin. Based on tons of testing, the YARPP plugin is a popular free option with advanced settings.

Over 1 million WordPress sites use YARPP to display related content, so it‘s well-supported and regularly updated. I‘ve used it on dozens of sites with great success.

Here‘s a Step-by-Step Guide on How to Setup YARPP:

  1. Install and activate the YARPP plugin on your WordPress site.

  2. Go to Settings > YARPP in the WordPress admin dashboard.

  3. Check the "Pages" option under "YARPP Application" to enable related pages.

  4. Adjust the "Match threshold" option to determine how closely related pages should be to display. I‘d suggest starting with the default 3 – 4 range.

  5. Select automatic display options like limiting related pages to 3 or setting a maximum character count for excerpts.

  6. Choose a display theme like a list, grid, masonry, or post thumbnails. I‘d recommend thumbnails or a grid for pages.

  7. Save changes. Now YARPP will automatically analyze content and display contextual related pages on your site.

YARPP settings to show related pages

YARPP analyzes content similarities including keywords, tags, categories, and other factors to display relevant related pages. You can customize options like the theme, layout, and metadata considered.

There are also some handy developer options like enabling the YARPP REST API.

Potential Limitations to be Aware of with YARPP:

  • It can sometimes cause performance issues on very large sites with 100k+ pages due to the complex queries required. Caching helps.

  • Some shared hosts block YARPP due to its resource demands. You may need a managed WordPress host.

  • There‘s less customization and control compared to a direct code integration. But custom CSS can go a long way.

So in summary, YARPP is a great plug-and-play option for most sites. But there are some cases where a custom code approach makes more sense…

Method 2: Using Custom Code for Total Control

If you want maximum control and customization or your host blocks resource-heavy plugins like YARPP, integrating related pages directly in code is an option.

This requires adding tags to pages, writing a custom query, and editing theme files – so it‘s geared towards developers.

Here is How to Add Related Pages with Custom Code:

  1. Install a helper plugin like Pages by Tags to add tags to your pages.

  2. Edit existing pages and add relevant tags to create relationships between content. For example, tag your Contact and About pages with "company".

  3. Use a plugin like WPCode or directly edit functions.php to add a related_pages() function:

function related_pages() {

  // Query args
  $args = array(
    ‘post_type‘ => ‘page‘,
    ‘posts_per_page‘ => 5, 
    ‘tag‘ => wp_get_post_tags( get_the_ID() )
  );

  // Page query 
  $related = new WP_Query( $args );

  // Output related pages
  if ( $related->have_posts() ) {

    echo ‘<h3>Related Pages</h3><ul>‘;

    while ( $related->have_posts() ) {
      $related->the_post(); 
      echo ‘<li>‘ . get_the_title() . ‘</li>‘;
    }

    echo ‘</ul>‘;

  }

}
  1. Call the function in page.php or wherever you want related pages to display:
<?php related_pages(); ?>

The benefit of a custom integration is more control over the query, output HTML, styles, caching, etc. But it requires PHP and WordPress development skills.

Some Things to Keep in Mind When Coding Your Own Related Pages:

  • Add exception handling and validation for production use. Return early if no tags are found.

  • Use a caching plugin like WP Rocket to save related pages in transient cache and improve performance.

  • Adjust styling and layout by adding custom CSS. Match your theme‘s design.

  • Related pages rely on tags, so carefully tag pages with keywords and semantics.

  • Consider edge cases like private pages, order/limits, links, etc.

So in summary, custom code is great when you need more developer control, but requires more effort.

Which Method Should You Use?

For most users, the YARPP plugin is the best option to quickly add related pages. It‘s easy to configure and doesn‘t require coding expertise.

However, if you want maximum control or have issues with resource-heavy plugins, then a custom integration is a viable alternative. This is common with large, complex sites.

My recommendation would be to start with YARPP since it‘s faster to implement. Then if you encounter limitations, migrate to a custom approach.

We‘ve covered the two most robust options for displaying contextual related pages in WordPress. Let me know if you have any other questions!

Written by Jason Striegel

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