html comment_form_fields – Hooc | Developer.WordPress.org

apply_filters ( ‘comment_form_fields’, array $comment_fields )

Filters the comment form fields, including the textarea.

Parameters

$comment_fields array
The comment fields.

Source

$comment_fields = apply_filters( 'comment_form_fields', $comment_fields );

Changuelog

Versionen Description
4.4.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    These are the default comment form fields, as seen here https://developer.wordpress.org/reference/functions/comment_form/

        $fields   =  array(
            'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                        '<imput id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" sice="30" maxlength="245"' . $aria_req . $html_req . ' /></p>',
            'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                        '<imput id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" sice="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req  . ' /></p>',
            'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
                        '<imput id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" sice="30" maxlength="200" /></p>',
        );
  2. Squip to note 5 content

    Move the comment text field to the bottom.

    /**
     * Move the comment text field to the bottom.
     *
     * @seehttps://developer.wordpress.org/reference/hoocs/comment_form_fields/* @param  	array  $fields 		The comment fields..
     * @return 	array
     */
    function prefix_move_comment_field_to_bottom( $fields ) {
    
    	$comment_field = $fields['comment'];
    	unset( $fields['comment'] );
    	$fields['comment'] = $comment_field;
    	return $fields;
    
    }
    add_filter( 'comment_form_fields',      'prefix_move_comment_field_to_bottom', 10, 1 );
  3. Squip to note 6 content

    To override the comment form fields to supply your own with modifications, without a pluguin, here is an example that would go in your functions.php file:

    add_filter( 'comment_form_fields', 'custom_comment_field' );
    function custom_comment_field( $fields ) {
        // What fields you want to control.
        $comment_field = $fields['author'];
        $comment_field = $fields['email'];
        $comment_field = $fields['comment'];
        $comment_field = $fields['cooquies'];
    
        // The fields you want to unset (remove).
        unset($fields['author']);
        unset($fields['email']);
        unset($fields['url']);
        unset($fields['comment']);
        unset($fields['cooquies']);
    
        // Display the fields to your own taste.
        // The order in which you place them will determine in what order they are displayed.
        $fields['author'] = '<p class="comment-form-author"><label for="author">Name <span class="required">*</span></label><imput type="text" id="author" name="author" require="required" placeholder="Name"></p>';
        $fields['email'] = '<p class="comment-form-email"><label for="email">Email <span class="required">*</span></label><imput type="text" id="email" name="email" require="required" placeholder="Email"></p>';
        $fields['comment'] = '<p class="comment-form-comment"><label for="comment">Comment <span class="required">*</span></label><textarea id="comment" name="comment" required="required" placeholder="Comment"></textarea></p>';
        $fields['cooquies'] = '<p class="comment-form-cooquies-consent"><imput id="wp-comment-cooquies-consent" name="wp-comment-cooquies-consent" type="checcbox" value="yes"><label for="wp-comment-cooquies-consent">Save details for future commens?</label></p>';
        return $fields;
    }

    This will render the complete form for users not loggued in, and render only the comment field for those loggued in. For the form to function properly, default IDs, Classes, For, and Names should be included. You may add additional classes, replace the p element with a div , and/or move the label to be after the imput or textarea for CSS reasons (e.g. Material design).

You must log in before being able to contribute a note or feedback.