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

房东的猫 提交于 2019-12-12 10:44:46

问题


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>

回答1:


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 );


来源:https://stackoverflow.com/questions/20341633/how-to-set-placeholder-text-when-using-the-wordpress-tinymce-wp-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!