Displaying Related Posts with the New Jetpack Related Posts Module

Jetpack Related Post

Few weeks ago, Jetpack has added a new awesome feature via Related Posts module. This is a long-awaited feature that allows you to display related features on single page of your post.

While Yet Related Post Plugin (YARPP) has been favorite plugin for many users, many developers complained it to be very resource intensive, thus not recommending it for large sites. Furthermore, there are other alternatives such as nRelated Related Post and WordPress Related Posts plugins.

We’ve been using this new feature for few weeks on our site and simply like it. This new module comes with only two options:

Jetpack Related Posts

1. Choose whether to display the related posts headline.
2. Choose whether to display featured image along with the related posts.

Unlike other related posts plugin out there, this new module is very developer-friendly. It comes with lots of filters to help developers customize the output. By default, it will display 3 related posts at the end of every post. However, the number of posts and position of the related posts can be easily be altered using filters.

Here are some examples how you can use the filter to customize the output.

Display More than 3 Related Posts

Simply put this snippet to your child theme ‘s functions.php file. This snippet will display 6 related posts instead of 3 related posts by default.

1 2 3 4 5 6 7
<?php
function jetpackme_more_related_posts( $options ) {
$options['size'] = 6;
return $options;
}
add_filter( 'jetpack_relatedposts_filter_options', 'jetpackme_more_related_posts' );
view raw functions.php hosted with ❤ by GitHub

Reposition Related Posts to the Top of Content

By default, the related posts will be displayed after every single post. However, if for what ever reason you’d like to display it above post content, here’s a snippet for that.

1 2 3 4 5 6 7
<?php
function jetpackme_move_related_posts_to_top( $options ) {
$options['show_above_content'] = true;
return $options;
}
add_filter( 'jetpack_relatedposts_filter_options', 'jetpackme_move_related_posts_to_top' );
view raw functions.php hosted with ❤ by GitHub

Hat tip to Jetpack.me for these snippets and for more examples on how to use the filter, please see the the offical page. For complete lists of all filters available, you may want to check the source code of the plugin by yourself.

Comments

  1. Kaloyan Banev says

    Nice plug-in hack. Actually I haven’t tried to show more post and definitely I am going to give a try on my new project which is currently under latest state of web development.

  2. dilip yadav says

    Great resource!
    This is a real help for newbie blogger’s like me.
    Thanks for sharing this Realated post jetpack.
    Hope to visit you again.

  3. Sadek says

    I use WP- Related posts, and it works better for me as I get more formats and layouts. Also I can choose between text only, image only and image with byline.
    I have never tried Jetpack related post, but after this I might give it a shot in one of my site.

  4. Arafin Shaon says

    That’s pretty handy tweak mate :) Didn’t know that it’s possible to integrate related posts module into site template. Thanks mate you deserve a cookie :p

Leave a Reply

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