# Placeholders in Comment Form Fields

> Adds helpful placeholder text to the comment, name, email and website fields of the comment form while keeping the visible labels for accessibility.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: comments, placeholders, ux
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/form-comment-placeholders/

## Code

```php
$wpide_comment_placeholders = array(
    'comment' => 'Share your thoughts…',
    'author'  => 'Your name',
    'email'   => 'you@example.com (never published)',
    'url'     => 'https://your-site.com (optional)',
);

$wpide_add_placeholder = function ( $html, $name ) use ( $wpide_comment_placeholders ) {
    if ( empty( $wpide_comment_placeholders[ $name ] ) || false !== strpos( $html, 'placeholder=' ) ) {
        return $html;
    }

    return preg_replace( '/<(input|textarea)\b/', '<$1 placeholder="' . esc_attr( $wpide_comment_placeholders[ $name ] ) . '"', $html, 1 );
};

add_filter( 'comment_form_default_fields', function ( $fields ) use ( $wpide_add_placeholder ) {
    foreach ( array( 'author', 'email', 'url' ) as $name ) {
        if ( isset( $fields[ $name ] ) ) {
            $fields[ $name ] = $wpide_add_placeholder( $fields[ $name ], $name );
        }
    }
    return $fields;
} );

add_filter( 'comment_form_defaults', function ( $defaults ) use ( $wpide_add_placeholder ) {
    $defaults['comment_field'] = $wpide_add_placeholder( $defaults['comment_field'], 'comment' );
    return $defaults;
} );
```

## Notes

Edit the texts at the top; placeholders never replace labels, so screen readers still announce each field.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Placeholders in Comment Form Fields" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
