WordPress.org

Ready to get started?Download WordPress

Forums

change comment form labels twenty eleven (6 posts)

  1. eagle8154
    Member
    Posted 2 years ago #

    In the theme twenty eleven, I would like to change the comment form title label, field labels, and, completely eliminate the website field.

    I'm using a twenty eleven child theme, and know to do the changes in comment.php, I just need to know how to write the code.

    Here is the code I found that will change everything except the comment form title:

    <?php $comment_args = array( 'fields' => apply_filters( 'comment_form_default_fields', array(
        'author' => '<p class="comment-form-author">' .
                    '<label for="author">' . __( 'Your Name' ) . '</label> ' .
                    ( $req ? '<span class="required">*</span>' : '' ) .
                    '<input id="author" name="author" type="text" value="' .
                    esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />' .
                    '</p><!-- #form-section-author .form-section -->',
        'email'  => '<p class="comment-form-email">' .
                    '<label for="email">' . __( 'Your Email' ) . '</label> ' .
                    ( $req ? '<span class="required">*</span>' : '' ) .
                    '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . 
    
    '" size="30"' . $aria_req . ' />' .
    		'</p><!-- #form-section-email .form-section -->',
        'url'    => '' ) ),
        'comment_field' => '<p class="comment-form-comment">' .
                    '<label for="comment">' . __( 'Let us know what you have to say:' ) . '</label>' .
                    '<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .
                    '</p><!-- #form-section-comment .form-section -->',
        'comment_notes_after' => '',
    );
    comment_form($comment_args); ?>

    and here is the code I found to change the form title label from "Leave A Reply":

    <?php comment_form(array('title_reply'=>'Please Post Your Comments & Reviews')); ?>

    I just need to know how to add the two together.

    Thanks,
    Jeff

  2. carbis
    Member
    Posted 2 years ago #

    Hi Jeff,

    Try this:

    <?php
    $comment_args = array(
    	'fields' => apply_filters(
    		'comment_form_default_fields', array(
    			'author' => '<p class="comment-form-author">' .
    				'<label for="author">' . __( 'Your Name' ) . '</label> ' .
    				( $req ? '<span class="required">*</span>' : '' ) .
    				'<input id="author" name="author" type="text" value="' .
    				esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />' .
    				'</p><!-- #form-section-author .form-section -->',
    			'email'  => '<p class="comment-form-email">' .
    				'<label for="email">' . __( 'Your Email' ) . '</label> ' .
    				( $req ? '<span class="required">*</span>' : '' ) .
    				'<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .
    				'" size="30"' . $aria_req . ' />' .
    				'</p><!-- #form-section-email .form-section -->',
    			'url'    => ''
    		)
    	),
    	'comment_field' => '<p class="comment-form-comment">' .
    		'<label for="comment">' . __( 'Let us know what you have to say:' ) . '</label>' .
    		'<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .
    		'</p><!-- #form-section-comment .form-section -->',
        'comment_notes_after' => '',
        'title_reply' => 'Please Post Your Comments & Reviews'
    );
    comment_form( $comment_args );
    ?>
  3. eagle8154
    Member
    Posted 2 years ago #

    It works perfect, Thanks!

  4. alistairwilson
    Member
    Posted 1 year ago #

    Hi Carbis

    I've had the same issue as Jeff, and your code helped a lot
    but there's some more bits to the form that I need to change:

    I'm missing the phrases "Your email address will not be published or shared." and "Required fields are marked*" and the "Post comment" button

    I've found this code:

    <?php $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' ); comment_form(array('title_reply'=>'Leave a note...','comment_notes_before'=>'<p class="comment-notes">' . __( 'Your email address will not be published or shared.' ) . ( $req ? $required_text : '' ) . '</p>'')); ?>

    but not the code for the post comment button yet, how would I add that to

    <?php
    $comment_args = array(
    	'fields' => apply_filters(
    		'comment_form_default_fields', array(
    			'author' => '<p class="comment-form-author">' .
    				'<label for="author">' . __( 'Your Name' ) . '</label> ' .
    				( $req ? '<span class="required">*</span>' : '' ) .
    				'<input id="author" name="author" type="text" value="' .
    				esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />' .
    				'</p><!-- #form-section-author .form-section -->',
    			'email'  => '<p class="comment-form-email">' .
    				'<label for="email">' . __( 'Your Email' ) . '</label> ' .
    				( $req ? '<span class="required">*</span>' : '' ) .
    				'<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .
    				'" size="30"' . $aria_req . ' />' .
    				'</p><!-- #form-section-email .form-section -->',
    			'url'    => ''
    		)
    	),
    	'comment_field' => '<p class="comment-form-comment">' .
    		'<label for="comment">' . __( 'Let us know what you have to say:' ) . '</label>' .
    		'<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .
    		'</p><!-- #form-section-comment .form-section -->',
        'comment_notes_after' => '',
        'title_reply' => 'Please Post Your Comments & Reviews'
    );
    comment_form( $comment_args );
    ?>
  5. carbis
    Member
    Posted 1 year ago #

    Hi alistairwilson,

    I've adjuted the code above (which changes the title label, field labels, and website field) to include your changes. I've added the 'comment_notes_before' argument to include the email address and required fields info, and the 'label_submit' arg for changing the text of the submit button. I haven't tested the code, but it should work fine.

    <?php
    $commenter = wp_get_current_commenter();
    $req = get_option( 'require_name_email' );
    $aria_req = ( $req ? " aria-required='true'" : '' );
    
    $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
    $comment_form_fields = apply_filters(
    	'comment_form_default_fields',
    	array(
    		'author' => '<p class="comment-form-author">' .
                        '<label for="author">' . __( 'Your Name' ) . '</label> ' .
                        ( $req ? '<span class="required">*</span>' : '' ) .
                        '<input id="author" name="author" type="text" value="' .
                        esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />' .
                        '</p><!-- #form-section-author .form-section -->',
    		'email'  => '<p class="comment-form-email">' .
                        '<label for="email">' . __( 'Your Email' ) . '</label> ' .
                        ( $req ? '<span class="required">*</span>' : '' ) .
                        '<input id="email" name="email" type="text" value="' .
                        esc_attr(  $commenter['comment_author_email'] ) .
                        '" size="30"' . $aria_req . ' />' .
                        '</p><!-- #form-section-email .form-section -->',
    		'url'    => ''
    	)
    );
    
    $comment_args = array(
    	'fields'               => $comment_form_fields,
    	'comment_field'        => '<p class="comment-form-comment">' .
                                  '<label for="comment">' . __( 'Let us know what you have to say:' ) . '</label>' .
                                  '<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .
                                  '</p><!-- #form-section-comment .form-section -->',
    	'comment_notes_before' => '<p class="comment-notes">' .
                                  __( 'Your email address will not be published or shared.' ) .
                                  ( $req ? $required_text : '' ) .
                                  '</p>',
    	'comment_notes_after'  => '',
    	'label_submit'         => 'Submit your comment',
    	'title_reply'          => 'Please Post Your Comments & Reviews'
    );
    
    comment_form( $comment_args );
    ?>
  6. ljmyers
    Member
    Posted 1 year ago #

    Great, thanks much for the code carbis.

Topic Closed

This topic has been closed to new replies.

About this Topic