Display related post in WordPress without plugin

There are a lot of ways to increase the number of people visits on your website. But the easiest of all is to display related posts at the end of every post. This will not only reduce your bounce rate as people might click through to read another post or two but will also increase the time people spend on your website. Both of which are a quality signal for Google. And ofcourse, it will increase your page views.

There are two methods available to show related post. First method is via using any good plugin and the second method is to do it manually. Here we’ll show you how you can show related post manually.

To add the functionality manually, you will have to add the following code to your theme wherever you want to show your related post. Usually we show related post at the end of the post.

<div class="related-posts-after-content">
  <h3>You Might Also Like</h3>
    $orig_post = $post;
    global $post;
    $tags = wp_get_post_tags($post->ID);
      $tag_ids = array();
      foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
        $args = array('tag__in'=>$tag_ids,'post__not_in'=>array($post->ID),
        $my_query = new wp_query($args);
          $my_query->the_post(); ?>
          <div class="related-thumb">
            <a rel="external" href="<?php the_permalink(); ?>">
              <?php the_post_thumbnail(array(150,100)); ?><br />
              <?php the_title(); ?>
        <?php }
     $post = $orig_post;



Leave a Reply

Your email address will not be published. Required fields are marked *