- This topic has 14 replies, 3 voices, and was last updated 1 year, 11 months ago by David.
-
AuthorPosts
-
May 18, 2020 at 2:15 am #1289677Eaydman
Hi,
I want to hide/delete the comment section from the post type.How can I do that ?
May 18, 2020 at 3:28 am #1289761DavidStaffCustomer SupportHi 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/
May 21, 2020 at 1:06 pm #1295912EaydmanThanks David π
May 21, 2020 at 3:38 pm #1296021DavidStaffCustomer SupportYou’re welcome
May 5, 2022 at 11:16 pm #2211051JeffI 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 CohanMay 5, 2022 at 11:38 pm #2211065Fernando Customer SupportHi Jeff,
Perhaps this article may be of assistance to you: https://njengah.com/disable-comments-custom-post-type/
Hope this helps! π
May 6, 2022 at 7:03 am #2211486JeffFeranando –
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' ); }
May 6, 2022 at 8:25 am #2211717JeffI 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.
May 6, 2022 at 8:31 am #2211727DavidStaffCustomer SupportHi there,
what if you try this for your condition
if ( 'wb_event' !== get_post_type() )
May 6, 2022 at 9:15 am #2211769JeffDavid –
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…May 6, 2022 at 9:22 am #2211782DavidStaffCustomer SupportIts the correct hook:
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');
May 6, 2022 at 9:23 am #2211783JeffI 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!
May 6, 2022 at 9:24 am #2211786DavidStaffCustomer SupportSee my reply above π Yours too will work as thats firing real late in the sequence.
Glad to hear its working
May 6, 2022 at 9:37 am #2211798JeffDavid –
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,
JeffMay 7, 2022 at 2:42 am #2212221DavidStaffCustomer SupportGlad to hear that is working !
-
AuthorPosts
- You must be logged in to reply to this topic.