Aller au contenu
FR

Disabling Comments on your Blog

Disabling Comments on your Blog
Version audio de cet article

With this tutorial, we will show you a function that allows you to disabled or tweak comments left on your website by users. The function users the comments_open filter.

Here’s the function for the condition: $post = get_post( $post_id ); and if $post->post_type correspond à post (which is the default post type for articles/posts), then the $open variable must return false.

Disabling comments on your blog

add_filter('comments_open', 'lenomdemafonction', 10, 2);
function lenomdemafonction( $open, $post_id ) {
$post = get_post( $post_id );
if ('post' == $post->post_type)
$open = false;
return $open;
}

We could also disable comments on your pages only; simply replace ‘post’ by ‘page’. For post types, simply had the post title instead of ‘post’.

Don’t forget that under Discussion settings, the option that allows users to leaves comments must be left unchecked.