Support » Plugin: Jetpack - WP Security, Backup, Speed, & Growth » Disabling Jetpack Related Posts for custom post types

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Animesh Gaurav

    (@bizanimesh)

    Hi @bobjones

    Jetpack Related posts shouldn’t appear on custom post types. Can you please go to your theme’s functions.php file or functionality plugin (you may have installed) and check for this code snippet:

    function jetpackme_allow_my_post_types( $allowed_post_types ) {
        $allowed_post_types[] = 'your-post-type';
     
        return $allowed_post_types;
    }
    add_filter( 'rest_api_allowed_post_types', 'jetpackme_allow_my_post_types' );

    If the above code is there, please remove it, and the related post should disappear from custom post types.

    In case if you don’t have the above code anywhere on your site and still related post is appearing, please copy and paste the below code in the theme’s function.php file or to a functionality plugin like Code Snippets.

    function jpina_no_related_posts( $options ) {
        if ( !is_singular( 'post' ) ) {
            $options['enabled'] = false;
        }
        return $options;
    }
    add_filter( 'jetpack_relatedposts_filter_options', 'jpina_no_related_posts' );

    Let us know how it went!

    Thread Starter bobjones

    (@bobjones)

    Thanks for your reply, Animesh.

    You correctly inferred that I’m using a plugin called Content Blocks (Custom Post Widget) to insert content blocks in my WordPress posts.

    Unfortunately, the function you provided has no effect when I add it to the plugin and crashes my site when I add it to my theme’s functions.php.

    JP Related Posts continue to appear in my content block and not on the post.

    I’m able to hide JP Related Posts (and JP Likes, for that matter) with CSS. Oddly, this hides related posts for the entire page, although I’ve targeted only the Content Blocks div. But at least related posts aren’t showing up in the content block.

    The Hide Jetpack Likes css works as intended, hiding JP Likes in the content block only.

    /* Hide Jetpack Related Posts for Content Blocks  */
    div.content_block .jp-relatedposts {
    	display: none !important;
    }
    
    /* Hide Jetpack Likes for Content Blocks  */
    div.content_block .jetpack-likes-widget-wrapper {
    	display: none;}
    • This reply was modified 4 months, 3 weeks ago by bobjones.
    Plugin Support Animesh Gaurav

    (@bizanimesh)

    Hi @bobjones

    We don’t recommend the CSS method because it will only disappear the Related Posts section from visitors but not completely remove it.

    Could you please try the code provided in the below link to disable Related Posts from specific posts?

    Again, I recommend you use the Code Snippets plugin to apply the code. Here’s how you can use the plugin: https://jetpack.com/support/adding-code-snippets

    Thread Starter bobjones

    (@bobjones)

    Animesh:

    Again, I want to block JP Related Posts for Content Block custom post types, not for WordPress posts. The Jetpack function to disable Related Posts for specific WordPress posts would not apply.

    Just for the heck of it, I used the Jetpack function to disable Related Posts with an individual content block id, but that had no effect.

    Plugin Contributor Stef

    (@erania-pinnera)

    Hi @bobjones!

    Would you like to try the code suggestion published here?

    Let me know how it goes!

    Thread Starter bobjones

    (@bobjones)

    Thanks for the link, Stef.

    The author’s function appears similar to the one provided by JetPack at Animesh’s link (https://jetpack.com/support/related-posts/customize-related-posts/#disable).

    This function is not ideal, as it blocks JP Related Posts in both the post and the content block that appears within the post, but at least related posts are not appearing in the content block.

    Thanks to all for the recommendations!

    • This reply was modified 4 months, 2 weeks ago by bobjones.
Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.