rajudhaka

Comment form customization

Aug 30th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. function my_update_comment_fields( $fields ) {
  2.  
  3.     $commenter = wp_get_current_commenter();
  4.     $req       = get_option( 'require_name_email' );
  5.     $label     = $req ? '*' : ' ' . __( '(optional)', 'text-domain' );
  6.     $aria_req  = $req ? "aria-required='true'" : '';
  7.  
  8.     $fields['author'] =
  9.         '<p class="comment-form-author">
  10.             <label for="author">' . __( "Name", "text-domain" ) . $label . '</label>
  11.             <input id="author" name="author" type="text" placeholder="' . esc_attr__( "Jane Doe", "text-domain" ) . '" value="' . esc_attr( $commenter['comment_author'] ) .
  12.         '" size="30" ' . $aria_req . ' />
  13.         </p>';
  14.  
  15.     $fields['email'] =
  16.         '<p class="comment-form-email">
  17.             <label for="email">' . __( "Email", "text-domain" ) . $label . '</label>
  18.             <input id="email" name="email" type="email" placeholder="' . esc_attr__( "[email protected]", "text-domain" ) . '" value="' . esc_attr( $commenter['comment_author_email'] ) .
  19.         '" size="30" ' . $aria_req . ' />
  20.         </p>';
  21.  
  22.     $fields['url'] =
  23.         '<p class="comment-form-url">
  24.             <label for="url">' . __( "Website", "text-domain" ) . '</label>
  25.             <input id="url" name="url" type="url"  placeholder="' . esc_attr__( "http://google.com", "text-domain" ) . '" value="' . esc_attr( $commenter['comment_author_url'] ) .
  26.         '" size="30" />
  27.             </p>';
  28.  
  29.     return $fields;
  30. }
  31. add_filter( 'comment_form_default_fields', 'my_update_comment_fields' );
  32.  
  33. // Comment field
  34.  
  35. function my_update_comment_field( $comment_field ) {
  36.  
  37.   $comment_field =
  38.     '<p class="comment-form-comment">
  39.            <label for="comment">' . __( "Comment", "text-domain" ) . '</label>
  40.            <textarea required id="comment" name="comment" placeholder="' . esc_attr__( "Enter comment here...", "text-domain" ) . '" cols="45" rows="8" aria-required="true"></textarea>
  41.        </p>';
  42.  
  43.   return $comment_field;
  44. }
  45. add_filter( 'comment_form_field_comment', 'my_update_comment_field' );
Add Comment
Please, Sign In to add comment