How to Show Related Posts in WordPress Without a Plugin?

Making your visitors go through each post increases the browsing time on your site and consequently, annoys the visitors. That is why related posts are important.

Related-Posts-without-Plugin

One of the most powerful strategies to convert your visitors into sales leads is to have better user navigation, which increases user engagement on the site and reduces bounce rate. Bounce rate basically is the percentage of users of a website who “bounce” or navigate away from a website, instead of continuing browsing on the same website. Bounce rate has an immense effect on search engine rankings as well as on your Google Adsense earnings.

Benefits of adding related posts feature

You want your visitors to read more of your content and in order to do so, you need to make it easier for them to navigate from one post to another.

The best solution to keep bounce rate low and user engagement high is to offer easier navigation by adding related posts. This way you can hit three targets with one arrow – increased user engagement, increased Adsense earnings, and reduced bounce rate.

Related posts are a great way to encourage users to stay on your website. It is also an ideal way to bring your older posts to notice which have been pushed off the record and no longer get enough traffic.

How to show related posts?

There are two ways of showing related posts in your WordPress website – displaying it with a plugin and without a plugin.

Well, as a matter of fact, it is easier to use a plugin than adding few lines of code in some file. However, adding a number of plugins on your website may slow down the performance and speed of your website which is why it is always recommended to avoid using a plugin.

Today in this article, we are going to show you how to add related posts without a plugin. It’s easier, simpler and requires little technical knowledge.

You need to open your single.php files in WordPress editor and paste these lines of code where you want to display related posts on your website.

Single.php

Single.php is a single post page where you can display just one post.

This code uses similar tags to display related posts.

ID);
if ($tags) {
        $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),
                'showposts'=>5, // Number of related posts that will be shown.
                'caller_get_posts'=>1
        );
        $my_query = new wp_query($args);
        if( $my_query->have_posts() ) {
                echo '

Related Posts

    '; while ($my_query->have_posts()) { $my_query->the_post(); ?>
  • '; } } ?>

To display related post according to different categories, use this code instead:

ID);
if ($categories) {
        $category_ids = array();
        foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
        
        $args=array(
                'category__in' => $category_ids,
                'post__not_in' => array($post->ID),
                'showposts'=>5, // Number of related posts that will be shown.
                'caller_get_posts'=>1
        );
       $my_query = new wp_query($args);
        if( $my_query->have_posts() ) {
                echo '

Related Posts

    '; while ($my_query->have_posts()) { $my_query->the_post(); ?>
  • '; } } ?>

Once added, check your website if it worked or not.

Author Bio:
Emma is a web developer by profession and works for Wordsuccor Ltd., a WordPress Web Development Service provider with a global reach. She loves innovative approach to WordPress development services and has a strong inclination for a suite of creative endeavour.

Recently Published

»

Is Your Business Site Fully Accessible?

Does your business site have full accessibility? Even with the ADA ...

»

Secure Web: 5 Best Practices For Application Development

There are several essential best practices for secure web ...

»

Laravel PHP Framework: Features and benefits for web development

Companies and organizations are focusing on developing custom web ...

»

Web Development Vs. Software Development: What Is the Difference?

As technology continues to transform all aspects of our lives, a lot ...

»

Web Redesign : Is Your Landing Page Begging for one?

How do you know when it’s time to web redesign your landing page? ...

»

Customer Acquisition: Few Steps To Improve This.

Customer acquisition is essential to any business’s success — to ...

»

Mobile App Development Tools: 5 Enterprise-Ready For Rapid Deployment

There are several enterprise-ready mobile app development tools for ...

»

Docker: How To Build Better Development Security With It

The top concern among developers and DevOps teams is security within ...

»

Mobile Development: How to Reduce Costs

Modern markets have become so competitive that it has become vital ...