Site logo

[Resolved] Disabling comments on custom post-type

Home Forums Support [Resolved] Disabling comments on custom post-type

Home Forums Support Disabling comments on custom post-type

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2136409
    Juste

    Hello.
    I’m trying to disable comments on custom post type with the following snippet but no luck.

    add_action('wp', 'jm_simple_comments', 15);
    
    function jm_simple_comments() {
      if( is_singular('mec-events') ) {
    		remove_action( 'generate_after_do_template_part', 'generate_do_comments_template', 15);	
    }

    Please help

    #2136452
    David
    Staff
    Customer Support

    Hi there,

    can you share a link to where i can see the CPT with Comments ?

    #2136481
    Juste

    here you go

    #2136485
    David
    Staff
    Customer Support

    OK so thats a template from the MEC plugin, so GP has no control over that.
    But i did find this which may be of use:

    https://webnus.net/dox/modern-events-calendar/removing-comment-box-on-single-event-in-modern-events-calendar/

    #2136490
    Juste

    howdy. I was mislead by the fact that filtering worked.
    Thanks.
    You are a saviour.

    #2136502
    David
    Staff
    Customer Support

    Glad to be of help

    #2136551
    Juste

    Acutally, in case anyone lands on this page, I found a universal useful bit here.

    function my_prefix_comments_open( $open, $post_id ) {
        $post_type = get_post_type( $post_id );
        // allow comments for built-in "post" post type
        if ( $post_type == 'post' ) {
            return true;
        }
        // disable comments for any other post types
        return false;
    }
    add_filter( 'comments_open', 'my_prefix_comments_open', 10 , 2 );

    The conditional check can even be outside of the handle and we just use add_filter( 'comments_open', function(){return false;} );
    Graceful.

    #2136561
    David
    Staff
    Customer Support

    Thanks for sharing that 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.