Skip Navigation

[Closed] hide comments in custom post type single page content template

This support ticket is created 9 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 2 voices.

Last updated by Shane 9 years ago.

Assisted by: Shane.

Author
Posts
#279247

I would like to have comments turned ON for my WordPress blog postings, but I would like comments turned OFF for all custom post type single page content templates.

I have created special single page content templates for my custom post types, but I don't see a place to turn off the comments - and they are showing up.

I don't want to turn off comments in my theme (Divi) because I want the comments for my standard WordPress posts.

Can you help?

Thanks.

Elise

#279391

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Elise,

To turn have the ability to turn on/off comments on your custom post type you will need to enable it in the Display section.

To do this go to Types -> Select your Custom Post Type and scroll down to Display Section.

Here you will need to ensure that the Comments checkbox is ticked.

This will allow you to enable/disable comments on your custom posts.

#279457

Thanks!

But once I've ticked the Comments checkbox, then how to I disable the comments on a specific custom post type?

Thanks!

Elise

#279463

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Elise,

You will need to do a bulk edit on the posts in the Custom Post Types.

To do this go to the custom post type and tick the box right beside 'title'.

In the drop down under above the box select edit then click apply.

Here you will be able to disable comments for all the selected posts just select "Do Not Allow"

#279471

I see how this can allow me to bulk edit current posts and turn off the comments.

However - what I want to do is to make sure that for ALL posts (in the future) for this particular custom post type, the comments will be OFF.

And I can't do that by disabling comments in the WordPress settings, because I want to keep the comments ON for regular WordPress Posts.

I found a thread online that suggest some code for the functions.php to accomplish this, and I tried it - but it didn't seem to have any effect:

function my_default_content( $post_content, $post ) {
if( $post->post_type )
switch( $post->post_type ) {
case 'contests':
case 'theatres':
case 'publicdomain':
case 'stories':
case 'press-releases':
case 'useful-links':
case 'performers':
$post->comment_status = 'closed';
break;
}
return $post_content;
}
add_filter( 'default_content', 'my_default_content', 10, 2 );

#279904

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Elise,

I did some test and found a way to get it to disable.

Please try using this function.

function default_comments_off( $data ) {
    if( $data['post_type'] == 'book') {
        $data['comment_status'] = 0;
    }

    return $data;
}
add_filter( 'wp_insert_post_data', 'default_comments_off' );

Add it to your theme's function.php file.

This should allow you to disable the comments for your custom post types.

#280096

Thanks - but just to be clear ...would I need to create a line for each one of my custom post types? And remember to add a line to the code every time I make a new custom post type?

So it would wind up looking like:

if ( $date['post_type'} == 'book') {
$data['comment_status'] = 0;
}
if ( $date['post_type'} == 'performer') {
$data['comment_status'] = 0;
}
if ( $date['post_type'} == 'theatre') {
$data['comment_status'] = 0;
}
and etc., for every single post type?

Or am I misunderstanding how to do this?

Thanks!

Elise

#280250

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Elise,

Yes having it like that should allow your post comments to be disabled when creating a new post.

This should allow any new posts that is created under any of the custom post types to have their comments disabled.

The topic ‘[Closed] hide comments in custom post type single page content template’ is closed to new replies.