Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Show Related Pages in WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Show Related Pages in WordPress

Recently, one of our users asked us if there was a way to show related pages instead of posts in WordPress. Previously, we showed you how to show related posts in WordPress with or without plugin. In this article, we will show you how to show related pages in WordPress.

Showing Related Pages in WordPress Using Plugin

The easier way to display related pages in WordPress is by using a plugin.

First thing you need to do is install and activate the Yet Another Related Posts Plugin (YARPP) plugin. After activation, you need to go to Settings » YARPP to configure the plugin.

Configue YARPP to only show related pages

On the plugin’s settings page, scroll down to ‘Display Options for your website’ section. Under Automatically Display option, you need to check ‘pages’ and leave posts and media unchecked. That’s all, you can save your settings now and YARPP will start displaying related pages below page content on your WordPress site.

Please note that YARPP along with some other WordPress plugins is blocked by some managed WordPress hosting providers due to its heavy database usage. Another issue that you may face is that YARPP cannot search database for text if your MySQL storage engine is set to InnoDB.

Showing Related Pages in WordPress Without Plugin

Before we show you how to display related pages without using a plugin, we would like you to take a look at our article on the difference between Posts and Pages in WordPress.

Most efficient way to display related posts is by looking for tags or categories. But since WordPress pages do not have tags or categories, we will first need to enable categories and tags for WordPress pages. To do that, all you need to do is install and activate, the Post Tags and Categories for Pages plugin.

The plugin works out of the box, so there are not settings for you to configure. Upon activation, it will simply enable tags and categories for your WordPress pages.

Now you need to edit a couple of pages you think are related to each other and add tags. For example, if you have a page about your company and another page for company’s history, you can tag them both as about us.

After you have added tags to a few pages, the next thing you need to do is to add this code in your theme’s functions.php file or a site-specific plugin.

function wpb_related_pages() { 
$orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag)
$tag_ids[] = $individual_tag->term_id;
'post_type' => 'page',
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
$my_query = new WP_Query( $args );
if( $my_query->have_posts() ) {
echo '<div id="relatedpages"><h3>Related Pages</h3><ul>';
while( $my_query->have_posts() ) {
$my_query->the_post(); ?>
<li><div class="relatedthumb"><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail('thumb'); ?></a></div>
<div class="relatedcontent">
<h3><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php the_time('M j, Y') ?>
<? }
echo '</ul></div>';
} else { 
echo "No Related Pages Found:";
$post = $orig_post;

This code looks for tags associated with a page and then runs a database query to fetch pages with the similar tags. To display the list of pages, you would need to edit your page template. Most commonly it is page.php or content-page.php file. Simply add this line of code where you want related pages to appear.

<?php wpb_related_pages(); ?> 

This will display related pages on any WordPress page. It will not look very pretty at first, so you will need to add some CSS and style it to match your theme.

Note: code in functions.php are treated the same as plugins.

We hope this article helped you display related pages in WordPress. As always, please feel free to ask us questions in the comments below. Don’t forget to follow us on twitter or join the discussion on Google+.

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. panos gew says:

    hey there. completely new, so i havea question, where should i put this line of code ->
    Do i have to put this line in functions.php as well?And if yes, i dont want related pages to show up in ANY SINGLE page…

    • WPBeginner Support says:

      No you need to put it in the template where you want to display related posts. Like single.php, category.php, etc.

  2. George says:

    Thank you! Works for me. :)

  3. WPBeginner Fan says:

    My question is what is the code for conditional statement? Something like function_exists ?

  4. Marcelo Luiz says:

    Would it be possible to get a list of pages sisters in a certain hierarchy of pages parents?

  5. Ayebal John Bob says:

    My major question is how do I put in that div that I will need to style in the css

  6. Rich says:

    To reiterate Al Harji’s comment, this tutorial was very timely as this was something I was starting on today with my site. However, when I went to install both YARPP and CRP, WP showed “not available” for both. I’m using GoDaddy’s Managed WP with 2014 theme. This is the first time I’ve received this message for any plugin. Checked the WP support forum but no luck. Any ideas?

  7. Gerald says:

    I was using YARPP for quite a while. The template part is really awesome but so far I didn’t thought about related PAGES. Great idea for an upcoming project. Thanks for the tip!

  8. Ajay says:


    Would like to pitch in my plugin Contextual Related Posts –

    You can use it to find related posts for posts, pages as well as other custom post types. It comes armed with a host of settings and some cool thumbnails style.

    • Al Harji says:

      Great tutorial as always, this one is so timely – thank you!

      Ajay, your plugin looks amazing. I am looking forward to trying it and also impressed with so many positive reviews. I use your Top 10 plugin which I love as well.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.