I want to force to show all fields (if possible these can pre-filled with user own e-mail and name data) to the logged-in users. So I found a reply on Wordpress Development/SE Community but I don't know how to figure it out. How can this be done?

1 Answer 1


you can paste the code below in your theme functions.php file, it should generate almost the same comment form for logged in and logged out users

add_filter( "comment_form_fields", function( $comment_fields ) {
    if( is_user_logged_in() ) {
        // Get an array of field names, excluding the textarea
        $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) );

        // Get the first and the last field name, excluding the textarea
        $first_field = reset( $comment_field_keys );
        $last_field  = end( $comment_field_keys );

        foreach ( $comment_fields as $name => $field ) {
            if ( 'comment' === $name ) {
                echo apply_filters( 'comment_form_field_comment', $field );
                //echo $args['comment_notes_after'];
            } else {
                if ( $first_field === $name ) {
                    do_action( 'comment_form_before_fields' );
                echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";

                if ( $last_field === $name ) {
                    do_action( 'comment_form_after_fields' );
        return array();
    return $comment_fields;
}, 2000 );

Note that i have not checked if the entered data in the form will be used when saving the comment you should check it (as WordPress might force use the user details saved in the profile).

  • It's worked! Thank you for the answer. 👊🏻
    – fatihturan
    Commented Jan 20, 2020 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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