I need to conditionally not show the comment form.
I’ve added a filter to comment_form_defaults
as follows:
function dont_show_comments($defaults) {
$defaults = array(
'fields' => array(),
'comment_field' => '',
'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
'logged_in_as' => '',
'comment_notes_before' => '',
'comment_notes_after' => '',
'id_form' => 'commentform',
'id_submit' => 'hide',
'title_reply' => __( 'You need to have accepted the terms to leave a reply' ),
'title_reply_to' => __( 'Leave a Reply %s' ),
'cancel_reply_link' => __( 'Cancel reply' ),
'label_submit' => '',
);
return $defaults;
}
This mostly works, but I’m left with an unlabelled button (the submit button).
What’s the best way of not showing the form at all – preferably via a hook, and preferably not using CSS.
I can think of only following ways to achieve this.