Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save luiseduardobraschi/3843940f97c8cc130d8f39f13a4d9c55 to your computer and use it in GitHub Desktop.
Save luiseduardobraschi/3843940f97c8cc130d8f39f13a4d9c55 to your computer and use it in GitHub Desktop.
Since WordPress uses difrerent templates for both logged and not logged-in users, I ended up having to use some other hooks other than the default filter.
<?php
function alter_comment_form_fields($fields){
$commenter = wp_get_current_commenter();
$fields['author'] = '<p class="comment-form-input comment-form-author"><label for="author">' . __( 'This is a fancy label', 'your-text-domain' ) . '</label><input id="author" required name="author" type="text" placeholder="Seu nome" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" aria-required="true" /></p>';
return $fields;
}
function logged_in_fields() {
echo implode('', alter_comment_form_fields(array()));
}
add_filter('comment_form_default_fields','alter_comment_form_fields');
add_action( 'comment_form_logged_in_after', 'logged_in_fields' );
add_action( 'comment_form_after_fields', 'logged_in_fields' ); // this one will do the same thing as the filter comment_form_default_fields; chose one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment