Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set placeholder text when using the WordPress TinyMCE wp_editor()

Can you set placeholder text for the TinyMCE textarea generated by wp_editor()?

http://codex.wordpress.org/Function_Reference/wp_editor

My code is currently:

$settings = array( 'media_buttons' => false );
wp_editor( $content, $editor_id, $settings );

This generates a textarea with all the bells and whistles such as TinyMCE buttons and Quicktags but I can't see how I can set placeholder text. With a standard textarea you can do it like so:

<textarea name="content" placeholder="Write something"></textarea>
like image 384
henrywright Avatar asked Dec 03 '13 02:12

henrywright


1 Answers

What follows won't give you an HTML5 "placeholder" attribute for your textarea but it will give you some text to display instead of an empty box:

I think usually you'd use wp_content by passing it all the bits and pieces it needs, like so:

wp_editor( stripslashes($content), $editor_id, $settings );

(The variable $content is a string which may have been obtained from the database or from a $_POST array, etc)

So i suggest that before you call the wp_content() function, test whether $content is empty and if you find that indeed it is, then you could seed it with placeholder content:

if( strlen( stripslashes($content)) == 0) $content = "Write something";
wp_editor( stripslashes($content), $editor_id, $settings );
like image 66
9 revs Avatar answered Sep 23 '22 10:09

9 revs