Title: Replace required asterisk with text
Last modified: August 20, 2016

---

# Replace required asterisk with text

 *  [Nick Ottens](https://wordpress.org/support/users/ottens/)
 * (@ottens)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/replace-required-asterisk-with-text/)
 * In my comment form, I’d like to replace the asterisk that denotes required fields
   with the text “Required” so, instead of,
 * > Name*
 * it looks like,
 * > Name (Required)
 * My comments.php calls the comments_form like this:
 * `<?php comment_form(); ?>`
 * I know I can add code to functions.php to change the layout of the form but I
   don’t know how to. Can someone help?

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/replace-required-asterisk-with-text/#post-2484935)
 * See [http://codex.wordpress.org/Function_Reference/comment_form](http://codex.wordpress.org/Function_Reference/comment_form)
 *  Thread Starter [Nick Ottens](https://wordpress.org/support/users/ottens/)
 * (@ottens)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/replace-required-asterisk-with-text/#post-2484960)
 * I found that but I can’t get it to work yet. I’m not that experienced at coding.
   If someone could show me an example, that would help.
 *  [jdavhar](https://wordpress.org/support/users/jdavhar/)
 * (@jdavhar)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/replace-required-asterisk-with-text/#post-2485166)
 * [http://www.1stwebdesigner.com/wordpress/comment-form-customization/](http://www.1stwebdesigner.com/wordpress/comment-form-customization/)
   
   May be helpful to you if the following isn’t.
 *     ```
       <?php $defaults = array( 'fields' => apply_filters( 'comment_form_default_fields', array(
           'author' => '<p class="comment-form-author">' .
                       '<label for="author">' . __( 'Name' ) . '</label> ' .
                       ( $req ? '<span class="required">*</span>' : '' ) .
                       '<input id="author" name="author" type="text" value="' .
                       esc_attr( $commenter['comment_author'] ) . '" size="30" tabindex="1"' . $aria_req . ' />' .
                       '</p><!-- #form-section-author .form-section -->',
           'email'  => '<p class="comment-form-email">' .
                       '<label for="email">' . __( 'Email' ) . '</label> ' .
                       ( $req ? '<span class="required">*</span>' : '' ) .
                       '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30" tabindex="2"' . $aria_req . ' />' .
                       '</p><!-- #form-section-email .form-section -->',
           'url'    => '
       <p class="comment-form-url">' .</p>
   
                       '<label for="url">' . __( 'Website' ) . '</label>' .
                       '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" tabindex="3" />' .
                       '
   
       <!-- #<span class="hiddenSpellError" pre="">form-section-url</span> .form-section -->' ) ),
           'comment_field' => '<p class="comment-form-comment">' .
                       '<label for="comment">' . __( 'Comment' ) . '</label>' .
                       '<textarea id="comment" name="comment" cols="45" rows="8" tabindex="4" aria-required="true"></textarea>' .
                       '</p><!-- #form-section-comment .form-section -->',
           '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' => '
       <p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%s">%s</a>. <a title="Log out of this account" href="%s">Log out?</a></p>
   
       ' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ),
           'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email is <em>never</em> published nor shared.' ) . ( $req ? __( ' Required fields are marked <span class="required">*</span>' ) : '' ) . '</p>',
           'comment_notes_after' => '<dl class="form-allowed-tags"><dt>' . __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:' ) . '</dt> <dd><code>' . allowed_tags() . '</code></dd>',
           'id_form' => 'commentform',
           'id_submit' => 'submit',
           'title_reply' => __( 'Leave a Reply' ),
           'title_reply_to' => __( 'Leave a Reply to %s' ),
           'cancel_reply_link' => __( 'Cancel reply' ),
           'label_submit' => __( 'Post Comment' ),
       ); ?>
       ```
   
 * those are defaults, here’s modified:
 *     ```
       <?php $defaults = array( 'fields' => apply_filters( 'comment_form_default_fields', array(
           'author' => '<p class="comment-form-author">' .
                       '<label for="author">' . __( 'Name' ) . '</label> ' .
                       ( $req ? '<span class="required">Required</span>' : '' ) .
                       '<input id="author" name="author" type="text" value="' .
                       esc_attr( $commenter['comment_author'] ) . '" size="30" tabindex="1"' . $aria_req . ' />' .
                       '</p><!-- #form-section-author .form-section -->',
           'email'  => '<p class="comment-form-email">' .
                       '<label for="email">' . __( 'Email' ) . '</label> ' .
                       ( $req ? '<span class="required">Required</span>' : '' ) .
                       '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30" tabindex="2"' . $aria_req . ' />' .
                       '</p><!-- #form-section-email .form-section -->',
           'url'    => '
       <p class="comment-form-url">' .</p>
   
                       '<label for="url">' . __( 'Website' ) . '</label>' .
                       '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" tabindex="3" />' .
                       '
   
       <!-- #<span class="hiddenSpellError" pre="">form-section-url</span> .form-section -->' ) ),
           'comment_field' => '<p class="comment-form-comment">' .
                       '<label for="comment">' . __( 'Comment' ) . '</label>' .
                       '<textarea id="comment" name="comment" cols="45" rows="8" tabindex="4" aria-required="true"></textarea>' .
                       '</p><!-- #form-section-comment .form-section -->',
           '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' => '
       <p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%s">%s</a>. <a title="Log out of this account" href="%s">Log out?</a></p>
   
       ' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ),
           'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email is <em>never</em> published nor shared.' ) . ( $req ? __( ' Required fields are marked <span class="required">Required</span>' ) : '' ) . '</p>',
           'comment_notes_after' => '<dl class="form-allowed-tags"><dt>' . __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:' ) . '</dt> <dd><code>' . allowed_tags() . '</code></dd>',
           'id_form' => 'commentform',
           'id_submit' => 'submit',
           'title_reply' => __( 'Leave a Reply' ),
           'title_reply_to' => __( 'Leave a Reply to %s' ),
           'cancel_reply_link' => __( 'Cancel reply' ),
           'label_submit' => __( 'Post Comment' ),
       ); ?>
       ```
   
 *  Thread Starter [Nick Ottens](https://wordpress.org/support/users/ottens/)
 * (@ottens)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/replace-required-asterisk-with-text/#post-2485168)
 * Thanks jdavhar. That means I have to put the full code of the comments form on
   my comments.php though where it currently just calls the form with a simple, 
   single line of code. I know it’s supposed to be possible to change specific things
   about the default form in the functions.php which would be a more elegant solution.
 *  [jdavhar](https://wordpress.org/support/users/jdavhar/)
 * (@jdavhar)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/replace-required-asterisk-with-text/#post-2485169)
 * Maybe this is what you’re looking for?
 *     ```
       <?php
       function comment_form_fixer($content){
       return str_replace('*', ' (Required)', $content);
       }
       add_filter('comment_form', 'comment_form_fixer');
       ?>
       ```
   
 *  Thread Starter [Nick Ottens](https://wordpress.org/support/users/ottens/)
 * (@ottens)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/replace-required-asterisk-with-text/#post-2485170)
 * I guess that should work but it doesn’t…
 *  [jdavhar](https://wordpress.org/support/users/jdavhar/)
 * (@jdavhar)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/replace-required-asterisk-with-text/#post-2485186)
 * Tested this one, works for sure:
 *     ```
       function modify_fields_required_marker($fields) {
       $commenter = wp_get_current_commenter();
       $req = get_option( 'require_name_email' );
       $aria_req = ( $req ? " aria-required='true'" : '' );
       $fields['author'] = '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required"> (Required)</span>' : '' ) .
       		         '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>';
       $fields['email'] = '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required"> (Required)</span>' : '' ) .
       		         '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>';
       $fields['url'] = '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' .
       		         '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>';
       return $fields;
       }
       add_filter('comment_form_default_fields','modify_fields_required_marker');
       ```
   
 *  [crystal awards](https://wordpress.org/support/users/crystal-awards/)
 * (@crystal-awards)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/replace-required-asterisk-with-text/#post-2485291)
 * Yeah, I would like to ask the same question as Ottens[.](http://www.okawards.com)
   I can’t get it to work yet. if anyone solve it, thanks!
 *  [favordeal](https://wordpress.org/support/users/favordeal/)
 * (@favordeal)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/replace-required-asterisk-with-text/#post-2485314)
 * I tested, I thought that should work but it still doesn’t[.](http://www.favordeal.com)..

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Replace required asterisk with text’ is closed to new replies.

## Tags

 * [comment](https://wordpress.org/support/topic-tag/comment/)
 * [Comments](https://wordpress.org/support/topic-tag/comments/)
 * [comment_form](https://wordpress.org/support/topic-tag/comment_form/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 9 replies
 * 5 participants
 * Last reply from: [favordeal](https://wordpress.org/support/users/favordeal/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/replace-required-asterisk-with-text/#post-2485314)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
