WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a protected-page plugin and want to disable comments on protected pages. I'm usually hooking into the_content but that's not enough for comments. I got into comments_array to block the existing comments, but how do I block comments_template?

share|improve this question
up vote 0 down vote accepted

You can control whether comments appear by filtering the comments_open() function. Here is an example from the WordPress codex:

add_filter( 'comments_open', 'my_comments_open', 10, 2 );
function my_comments_open( $open, $post_id ) {

    $post = get_post( $post_id );

    if ( 'page' == $post->post_type )
        $open = false;

    return $open;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.