0

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?

0

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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