Remove Jetpack Related Post from Custom Post Types

WordPressPosted on

1 min read

Jetpack’s related posts is a great tool to show a similar post for the current article. Generate related post is not just as easy, you can’t just query a similar category for more content.

Jetpack has an advanced algorithm which servers the most similar posts right under – or somewhere else – your posts. By default, it will show on your Custom Post Types which in some cases, not the most ideal. Luckily it is easy to turn it off!

function pine_jetpack_archive_no_related_posts( $options ) {
    if ( is_post_type_archive( 'product' ) || ( get_post_type() == 'product' && is_single() ) ) {
        $options['enabled'] = false;
    }
    return $options;
}

add_filter( 'jetpack_relatedposts_filter_options', 'pine_jetpack_archive_no_related_posts' );

As you see we use the jetpack_relatedposts_filter_options filter witch a simple CPT condition with the help of is_post_type_archive() function. If the condition is true we set the $options[‘enabled’] to false.

Need a web developer? Maybe we can help, get in touch!

Looking for web dev job?
You can check them on Jooble.

To see and write comments, you must allow the related (Disqus) cookies. For more information, please visit our privacy policy page.

Similar Posts

More content in WordPress category