i would like to add placeholder when using wp_editor()
function.
I tried to pass placeholder attribute in textarea, but didn't work. I tried to pass it in settings
wp_editor(
$project_description ,
'project_description',
array(
'wpautop' => true,
'media_buttons' => false,
'textarea_name' => 'project_description',
'editor_class' => 'is-project-description-textarea',
'textarea_rows' => 5,
//'textarea_placeholder' => 'Project Description WP Editor Default',
'placeholder' => 'Project Description WP Editor Default 2'
)
);
I checked then the _WP_Editors::parse_settings( string $editor_id, array $settings ): array
Also tried to replace <textarea
with <textarea placeholder="
$wpEditorPlaceholder = 'My Placeholder';
$wpEditor = wp_editor(
$project_description ,
'project_description',
array(
'wpautop' => true,
'media_buttons' => false,
'textarea_name' => 'project_description',
'editor_class' => 'is-project-description-textarea',
'textarea_rows' => 5,
)
);
$wpEditorNew = str_replace('<textarea', '<textarea placeholder="' . $wpEditorPlaceholder . '" ', $wpEditor);
echo $wpEditorNew;
but didn't work and then i added it via add_action
add_action('the_editor', 'add_placeholder_to_editor');
function add_placeholder_to_editor($editorMarkup)
{
if (str_contains($editorMarkup, 'is-project-description-textarea')) {
$editorMarkup = str_replace('<textarea', '<textarea placeholder="Hello"', $editorMarkup);
}
return $editorMarkup;
}
Placeholder added successfully but it didn't show it when js loaded
Then i thought to add tinymce in settings
wp_editor(
$project_description ,
'project_description',
array(
'wpautop' => true,
'media_buttons' => false,
'textarea_name' => 'project_description',
'editor_class' => 'is-project-description-textarea',
'textarea_rows' => 5,
'tinymce' => array(
'paste_as_text' => true,
'placeholder' => 'Project Description',
)
)
);
Key paste_as_text
worked but key placeholder
didn't work.
What i miss? How can i add placeholder attribute?