[Resolved] Comment fields placeholders

Home Forums Support [Resolved] Comment fields placeholders

Home Forums Support Comment fields placeholders

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #584184
    pancakebg

    Hey guys, can you help me to change the text on the placeholders in the comments section?

    I need to replace the name, e-mail and if possible to remove the website field.

    Also i would like to know if i can change the text on this: Save my name, email, and website in this browser for the next time I comment.

    I already found this posted by Tom but when i add it to the child theme function.php and replace the fields – nothing happens.

    add_filter( 'comment_form_default_fields', 'tu_adjust_comment_form_fields' );
    function tu_adjust_comment_form_fields( $fields ) {
        return array(
            'author' => '<label for="author" class="screen-reader-text">' . esc_html__( 'Name', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Name', 'generatepress' ) . ' *" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" />',
            'email' => '<label for="email" class="screen-reader-text">' . esc_html__( 'Email', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Email', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />',
            'url' => '<label for="url" class="screen-reader-text">' . esc_html__( 'Website', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Website', 'generatepress' ) . '" id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" />',
        );
    }

    Thank you! πŸ™‚

    #584547
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You can try something like this:

    add_filter( 'comment_form_default_fields', 'tu_filter_comment_fields' );
    function tu_filter_comment_fields( $fields ) {
        $commenter = wp_get_current_commenter();
    
        $fields['author'] = '<label for="author" class="screen-reader-text">' . esc_html__( 'Name', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Name', 'generatepress' ) . ' *" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" />';
    
        $fields['email'] = '<label for="email" class="screen-reader-text">' . esc_html__( 'Email', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Email', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />';
    
        $consent   = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
    
        $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . '<label for="wp-comment-cookies-consent">Your modified text here</label></p>';
    	
        unset( $fields['url'] );
    
        return $fields;
    }
    #584678
    pancakebg

    Sadly, it does not work for me.

    The placeholders did not changed.

    The box with the URL still there.

    However, the “Save my name, email, and website in this browser for the next time I comment.” did changed but the check box goes between the “Name” and “Email” boxes on the upper row.

    That’s a bit hard to figure it out how to do it. ;[

    #584709
    Leo
    Staff
    Customer Support

    Is the code still added?

    I tested the same code using Code Snippets and everything worked for me.

    #584725
    pancakebg

    I removed it but i will add it back so you can check it out.

    Thanks! πŸ™‚

    #584870
    Tom
    Lead Developer
    Lead Developer

    Can you share the code with the changes you added to your site?

    #584940
    pancakebg

    Yes, here is the code:

    add_filter( 'comment_form_default_fields', 'tu_filter_comment_fields' );
    function tu_filter_comment_fields( $fields ) {
        $commenter = wp_get_current_commenter();
    
        $fields['author'] = '<label for="author" class="screen-reader-text">' . esc_html__( 'Name', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'NEW NAME HERE', 'generatepress' ) . ' *" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" />';
    
        $fields['email'] = '<label for="email" class="screen-reader-text">' . esc_html__( 'Email', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'NEW EMAIL HERE', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />';
    
        $consent   = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
    
        $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . '<label for="wp-comment-cookies-consent">TEXT FOR CHECKBOX HERE</label></p>';
    	
        unset( $fields['url'] );
    
        return $fields;
    }
    #585194
    Tom
    Lead Developer
    Lead Developer

    And this is being added to your child theme?

    Any other functions/changes made to template files regarding the comments area?

    Maybe try this:

    add_filter( 'comment_form_default_fields', 'tu_filter_comment_fields', 20 );
    function tu_filter_comment_fields( $fields ) {
        $commenter = wp_get_current_commenter();
    
        $fields['author'] = '<label for="author" class="screen-reader-text">' . esc_html__( 'Name', 'generatepress' ) . '</label><input placeholder="NEW NAME HERE *" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" />';
    
        $fields['email'] = '<label for="email" class="screen-reader-text">' . esc_html__( 'Email', 'generatepress' ) . '</label><input placeholder="NEW EMAIL HERE *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />';
    
        $consent   = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
    
        $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . '<label for="wp-comment-cookies-consent">TEXT FOR CHECKBOX HERE</label></p>';
    	
        unset( $fields['url'] );
    
        return $fields;
    }
    #585256
    pancakebg

    Thanks Tom!

    I have a bit of success with the last one but the check box still between the two fields

    I have no problem to remove this box if you know how to do it.

    For the fields i use this css:

    @media (min-width: 769px) {
        .comment-form #author, 
        .comment-form #email {
            width: 48%;
            float: left;
        }
        .comment-form #email {
            float: right;
        }
        .comment-form #url {
            width: 100%;
        }
    }

    I also have few added filters in the function.php about the comments mainly to change the names.

    The code is up and you can check the site.

    Thank you!

    #585434
    Tom
    Lead Developer
    Lead Developer

    Try this CSS:

    .comment-form-cookies-consent {
        clear: both;
    }
    #585695
    pancakebg

    Works great, thank you!

    #585752
    Tom
    Lead Developer
    Lead Developer

    No problem! πŸ™‚

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.