• Resolved shalintj

    (@shalintj)


    Hi,

    I want to disable Jetpack Related Posts from all the posts of a specific category. How do I do that. Here’s what I tried inside my functions.php:

    function jetpackme_no_related_posts( $options ) {
        if ( array( 'category.slug' => 'my-category-slug' ) ) {
            $options['enabled'] = false;
        }
        return $options;
    }
    add_filter( 'jetpack_relatedposts_filter_options', 'jetpackme_no_related_posts' );

    Website: https://sarkarilife.com

    https://www.ads-software.com/plugins/jetpack/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Try the code mentioned here to exclude a category from your Related Posts:
    https://jetpack.me/support/related-posts/customize-related-posts/#exclude-cats

    Thread Starter shalintj

    (@shalintj)

    Hi Jeremy,

    Thanks for the reply..

    Unfortunately looks like I was not able to put across my query well. What you’ve answered is:

    “How to exclude an entire category from ever appearing among Related Posts results”,
    however what I’m actually looking for is this:

    “How to selectively disable Related Posts from appearing on all the posts of a specific category”

    For clarity, I’ve used the same terminologies as was mentioned on your support page available at https://jetpack.me/support/related-posts/customize-related-posts

    I look forward to your reply.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    In this case, you can use this code:
    https://jetpack.me/support/related-posts/customize-related-posts/#delete

    You will, however, want to wrap remove_filter( 'the_content', $callback, 40 ); in a conditional tag using in_category:
    https://codex.www.ads-software.com/Function_Reference/in_category

    Thread Starter shalintj

    (@shalintj)

    Hi Jeremy,

    I missed this reply.. Thanks for your reply.

    Can you help me out with the exact code to selectively disable Related Posts from appearing on all the posts of a couple of categories. I’m not a programmer and hence not able to figure what exactly is to be dove. Having said that, I can definitely put the code that you will provide under functions.php.

    Sample name for categories – CatA, CatB, etc.

    I look forward to your help..

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Something like this should do the trick:

    function jetpackme_remove_rp() {
        $jprp = Jetpack_RelatedPosts::init();
        $callback = array( $jprp, 'filter_add_target_to_dom' );
        if ( in_category( array( 'CatA', 'CatA' ) ) ) {
            remove_filter( 'the_content', $callback, 40 );
        }
    }
    add_filter( 'wp', 'jetpackme_remove_rp', 20 );

    Hi,

    I wanted to remove Jetpack Related posts from all posts within a specific category. I and another WordPress developer came up with the following solution:

    //Remove Jetpack Related Posts form Posts in a Category

    if ( class_exists('Jetpack_RelatedPosts')) {
    
        function jetpackme_remove_rp() {
            $jprp = Jetpack_RelatedPosts::init();
            $callback = array($jprp, 'filter_add_target_to_dom');
            if (in_category(array(243))) {
                remove_filter('the_content', $callback, 40);
            }
        }
    
        add_action('wp', 'jetpackme_remove_rp', 20);
    }

    I am using my category id. It can be replaced with your own category id.

    How can I exclude all categories except one category called “blog” to show up only. I am having issues pointing a specific category to the related post.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    @crazy Could you please start your own thread, as per the Forum Welcome?
    https://www.ads-software.com/support/plugin/jetpack#postform

    Thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to exclude Related posts from all the posts of a category?’ is closed to new replies.