如何在使用WordPress TinyMCE时设置占位符文本wp_editor()

hen*_*ght 6 php forms wordpress tinymce

您可以为生成的TinyMCE textarea设置占位符文本wp_editor()吗?

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

我的代码目前是:

$settings = array( 'media_buttons' => false );
wp_editor( $content, $editor_id, $settings );
Run Code Online (Sandbox Code Playgroud)

这会产生一个带有所有铃声和口哨声的文本区域,例如TinyMCE按钮和Quicktags,但我看不出如何设置占位符文本.使用标准文本区域,您可以这样做:

<textarea name="content" placeholder="Write something"></textarea>
Run Code Online (Sandbox Code Playgroud)

owe*_*mck 1

下面的内容不会"placeholder"为您的文本区域提供 HTML5 属性,但它会给您一些要显示的文本而不是空框:

我认为通常您会通过传递它需要的所有片段来使用 wp_content ,如下所示:

wp_editor( stripslashes($content), $editor_id, $settings );
Run Code Online (Sandbox Code Playgroud)

(变量是一个字符串,可能是从数据库或数组等$content中获取的)$_POST

因此,我建议在调用该wp_content()函数之前,测试是否$content为空,如果发现确实为空,则可以使用占位符内容为其播种:

if( strlen( stripslashes($content)) == 0) $content = "Write something";
wp_editor( stripslashes($content), $editor_id, $settings );
Run Code Online (Sandbox Code Playgroud)