Site logo

Archived topic

Want To Off Comment Some Category

9 replies · Started by Mehedi on December 12, 2020

Viewing posts 1–10 of 10

Hello Sir,
hope you are doing well.i want to off comment box for some Category. Suppose My Category Name "Example Category"and Category id 100,So How Can off comment for this category?
Thanks & Regards,
Mehedi

Hi there,

You could do this:

add_filter( 'comments_open', function( $open, $post_id ) {
    if ( has_category( 100, $post_id ) ) {
        $open = false;
    }

    return $open;
}, 10, 2 );

Function Not Working,when i add its functions.php all single post not open,i see blank page.
Thanks

Can you try it now?

Yes working sir,but my category id 98,99, i says 100 for example,i want to use any category id(single or multiple).just replace category id for On & Off comment.when i replace category id wp says syntax error.
Thanks & Regards,
Mehedi

Hi,

Did you place the category IDs properly?

You'll have to place the multiple IDs as an array.

example:

add_filter( 'comments_open', function( $open, $post_id ) {
    if ( has_category( array(98,99), $post_id ) ) {
        $open = false;
    }

    return $open;
}, 10, 2 );

Alternatively, you can use slugs or names.

Example:

add_filter( 'comments_open', function( $open, $post_id ) {
    if ( has_category( array('category_slug_1','category_slug_2'), $post_id ) ) {
        $open = false;
    }

    return $open;
}, 10, 2 );

Wow! Working ,i need more one help. i use DC Simple Share Buttons Plugins[https://wordpress.org/plugins/dc-simple-share-buttons/] For Social Share,i want to disabled Share option for Specific category, Like: Category ID: 98 How Can i Disabled that.
Thanks & Regards,
Mehedi

Wow! Working ,i need more one help. i use DC Simple Share Buttons Plugins[https://wordpress.org/plugins/dc-simple-share-buttons/] For Social Share,i want to disabled Share option for Specific category, Like: Category ID: 98 How Can i Disabled that.

Unfortunately, DC Simple Share Buttons is a third party plugin that is not within our scope of support.

But to point you to a potential solution.

If you want it hidden, you can do it with CSS placed within a Hook Element.

Create a Hook Element and add this inside a Hook Element's code area:

<style>
.entry-content > .myclass {
    display: none;
}
</style>

You then set the Hook Element's Display rule to the category you want this applied to.

If you want it visible but disabled, you'll need custom scripts.

Wow Working! Thank You So Much.
Regards,
Mehedi

No problem. Glad to be of any help. :D

This archived topic is closed to new replies.