Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.