I need to add placeholder="Write a Comment"
for default comments form
<div class="comment-field_box">
<?php
comment_form(array(
'title_reply' => '',
'comment_notes_after' => '',
'label_submit' => 'Publish',
));
?>
</div>
I tried this tip but it didn't work for me.
function custom_comment_form_placeholders( $fields ) {
if ( isset( $fields['comment'] ) ) {
$fields['comment'] = str_replace(
'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required=""></textarea>',
'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="" placeholder="Write a Comment"></textarea>',
$fields['comment']
);
}
return $fields;
}
add_filter( 'comment_form_defaults', 'custom_comment_form_placeholders' );
I need to add placeholder="Write a Comment"
for default comments form
<div class="comment-field_box">
<?php
comment_form(array(
'title_reply' => '',
'comment_notes_after' => '',
'label_submit' => 'Publish',
));
?>
</div>
I tried this tip but it didn't work for me.
function custom_comment_form_placeholders( $fields ) {
if ( isset( $fields['comment'] ) ) {
$fields['comment'] = str_replace(
'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required=""></textarea>',
'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="" placeholder="Write a Comment"></textarea>',
$fields['comment']
);
}
return $fields;
}
add_filter( 'comment_form_defaults', 'custom_comment_form_placeholders' );
Use the filter comment_form_fields
instead of comment_form_defaults
. Also, in the call to str_replace()
, remove the =""
from required
in both strings. So, your code will become:
function custom_comment_form_placeholders( $fields ) {
if ( isset( $fields['comment'] ) ) {
$fields['comment'] = str_replace(
'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required></textarea>',
'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required placeholder="Write a Comment"></textarea>',
$fields['comment']
);
}
return $fields;
}
add_filter( 'comment_form_fields', 'custom_comment_form_placeholders' );