How to Remove Jetpack’s Related Post on Custom Post Types (CPT)

One of my favourite features of Jetpack is Related Posts module. It allows users to easily display related posts without any hassle. It’s developer-friendly and highly customizable with lots of filters available to customize the output of the related posts.

Thankfully, the Jetpack team have already provided some nice tutorials and examples on customizing the related posts output.

While developing and designing our current theme, we noticed that we needed to remove the related posts from being displayed from our Themes page and its archive pages. We’re happy to share the code we use on our site. Please note that our custom post types (CPT) is “themes”, so if you wish to use it simply replace the “themes” CPT with your own CPT name.

<pre><?php

//* Remove Jetpack Related Posts on THEMES CPT
function afn_jetpack_archive_no_related_posts( $options ) {
    if ( is_post_type_archive( 'themes' ) ) {
        $options['enabled'] = false;
    }
    return $options;
}
add_filter( 'jetpack_relatedposts_filter_options', 'afn_jetpack_archive_no_related_posts' );

//* Remove Jetpack Related Posts on THEMES Single Page
function afn_jetpack_singular_no_related_posts( $options ) {
    if ( is_singular( 'themes' ) ) {
        $options['enabled'] = false;
    }
    return $options;
}
add_filter( 'jetpack_relatedposts_filter_options', 'afn_jetpack_singular_no_related_posts' );</pre>

The first part of code removes the related posts on CPT archive page while the second part of code remove the related posts on single page of the CPT. The jetpack_relatedposts_filter_options filter does all the magic here.

If you’ve any question about Jetpack, feel free to post your questions in the support forum. For more examples on customizing the Related Posts module, check out the link we mentioned above.

If you haven’t use Jetpack, we recommend to take a look at all the modules it provides it comes with. If you like this article, feel free to share it with your friends or colleagues.

Get more stuff like this

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Leave a Reply

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.