[Resolved] Add placeholder to comment textarea field

Home Forums Support [Resolved] Add placeholder to comment textarea field

Home Forums Support Add placeholder to comment textarea field

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1508128
    George

    Is there a function to add a placeholder in the comment form textarea field?

    The following code doesn’t work:

    add_filter( 'comment_form_defaults', 'gm_textarea_placeholder' );
      
    function gm_textarea_placeholder( $fields ) {
        $fields['comment_field'] = str_replace(
            '<textarea',
            '<textarea placeholder="Comment"',
            $fields['comment_field']
        );
    
    	return $fields;
    }
    #1508198
    Leo
    Staff
    Customer Support

    Hi George,

    The comment is field is handled by WordPress and I found this article that might help?
    https://pupungbp.com/add-placeholder-to-your-comment-form-in-wordpress/

    #1508199
    George

    Yes, Leo, I have tried everything, nothing works!

    #1508204
    Leo
    Staff
    Customer Support

    Any chance you can check with WordPress’ support team first and see if they can provide any quick pointers?

    #1508206
    George

    Oh really? Not hoping to get a reply any time soon from them. Damn, didn’t think it was that complicated! Maybe somehow GP overrides those settings? I have tried a lot of code that should work but it doesn’t.

    #1508209
    Leo
    Staff
    Customer Support

    I don’t think so but definitely could be wrong πŸ™‚

    Did you test if the same code works in a twenty series WP theme?

    Let me know πŸ™‚

    #1508212
    George

    Doesn’t work on a default theme, either. The yourdomain needs to be placed by generatepress, right?

    #1508222
    George
    #1508224
    Leo
    Staff
    Customer Support

    What about this:

    add_filter( 'comment_form_defaults', function( $defaults ) {
        $defaults['comment_field'] = sprintf(
            '<p class="comment-form-comment"><label for="comment" class="screen-reader-text">%1$s</label><textarea placeholder="PLACE HOLDER TEXT HERE" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
            esc_html__( 'Comment', 'generatepress' )
        );
    
        return $defaults;
    }, 20 );
    #1508233
    George

    Yes, that’s it, it was the priority!

    This one also works now:

     function placeholder_comment_form_field($fields) {
        $replace_comment = __('Your Comment', 'generatepress');
         
        $fields['comment_field'] = '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) .
        '</label><textarea id="comment" name="comment" cols="45" rows="8" placeholder="'.$replace_comment.'" aria-required="true"></textarea></p>';
        
        return $fields;
     }
    add_filter( 'comment_form_defaults', 'placeholder_comment_form_field', 20 );

    Leo, you are a savior, thank you!

    #1508237
    Leo
    Staff
    Customer Support

    No problem πŸ™‚

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