[Resolved] Dissable Comments

Home Forums Support [Resolved] Dissable Comments

Home Forums Support Dissable Comments

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1289677
    Eaydman

    Hi,
    I want to hide/delete the comment section from the post type.

    How can I do that ?

    #1289761
    David
    Staff
    Customer Support

    Hi there,

    is that the default WordPress Post ? OR a custom post type.

    This is great guide for all things related to getting rid of comments:

    https://www.wpbeginner.com/wp-tutorials/how-to-completely-disable-comments-in-wordpress/

    #1295912
    Eaydman

    Thanks David πŸ™‚

    #1296021
    David
    Staff
    Customer Support

    You’re welcome

    #2211051
    Jeff

    I have a CPT ‘wb_event’. I want to disable comments for the single page.

    The “Disable Comments” plugin works. Surely, however, there’s a way to do this with code.

    I’ve tried:
    1. removing “comments” from the “supports” arg, where the CPT is defined
    2. Using a function that does a remove_post_type_support(‘wb_event’, ‘comments’), with:
    add_action(‘init’, {function_name}). I’ve tried this both in the child theme’s functions file and in a file in mu-plugins.

    Neither works.

    Please advise. Thanks.
    Jeff Cohan

    #2211065
    Fernando
    Customer Support

    Hi Jeff,

    Perhaps this article may be of assistance to you: https://njengah.com/disable-comments-custom-post-type/

    Hope this helps! πŸ™‚

    #2211486
    Jeff

    Feranando –

    I had read that article prior to adding my above comment. It’s what steered me to the “remove_post_type_support()” solution β€” which I’ve tried but which does not work.

    Can you think of any reasons remove_post_type_support() would not work?

    Here’s my code, currently in a file in mu-plugins/:

    add_action( 'init', 'remove_custom_post_type_comments' );
    function remove_custom_post_type_comments() {
    	remove_post_type_support( 'wb_event', 'comments' );
    }
    #2211717
    Jeff

    I think the answer to my question is that remove_post_type_support() applies to the edit screen.
    Also, the comments feature apparently applies only to diplaying comment count.

    So, now I’m trying this:

    add_action ('init', 'jdc_remove_comment_template');
    function jdc_remove_comment_template() {
    	if ( ! is_singular( 'wb_event' ) ) return;
    	remove_action( 'generate_after_do_template_part', 'generate_do_comments_template', 15 );
    }

    Although the if condition isn’t working, the remove_action line does work if I comment out the if condition.

    #2211727
    David
    Staff
    Customer Support

    Hi there,

    what if you try this for your condition

    if ( 'wb_event' !== get_post_type() )

    #2211769
    Jeff

    David –

    I did try that, too.
    if ( 'wb_event' != get_post_type() ) return;
    Still no love.
    The code is now in child theme’s functions.php
    I’m thinking:

    1. I might be using the wrong hook for the remove_action(). Thoughts?

    2. I might be using the wrong hook or priority for the add_action()
    I’ve also tried after_theme_setup and wp_loaded. If so, it’s not a GeneratePress question…

    #2211782
    David
    Staff
    Customer Support

    Its the correct hook:

    https://github.com/tomusborne/generatepress/blob/a3ce1712ab1cc705fed577fad8fa9ea8c04d5d20/inc/structure/comments.php#L192

    which is proven as you say it works without the condition. And if that condition is correct then is suspect its:

    add_action ('init', 'jdc_remove_comment_template');

    the init fires real early before a lot of the post queries. Try:

    add_action ('wp', 'jdc_remove_comment_template');

    #2211783
    Jeff

    I think I solved it by changing the hook for the add_action to “get_template_part_content“.

    I say “think” because I need to investigate and confirm that the comments template hasn’t been removed for other post types; but an initial quick inspection indicates success.

    Thanks!

    #2211786
    David
    Staff
    Customer Support

    See my reply above πŸ™‚ Yours too will work as thats firing real late in the sequence.

    Glad to hear its working

    #2211798
    Jeff

    David –

    I just now saw your 9:22am comment. Thank you.

    I do see what you mean (that the “init” is the correct hook beause the comments form IS removed if I disable the post-type condition and use init as the hook for the add_action). But when I do that, the comments form is removed for BLOG POSTS, too (and I’m assuming for other post types).

    The only thing that’s worked for me so far (i.e., comments form removed ONLY FOR this CPT) is when I used the get_template_part_content as the hook for the add_action.

    I doesn’t make sense to me. But as you suggested, if my solution isn’t broken, I’m not going to spend more time trying to fix it.

    Cheers,
    Jeff

    #2212221
    David
    Staff
    Customer Support

    Glad to hear that is working !

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