【问题标题】:How to set placeholder text when using the WordPress TinyMCE wp_editor()使用 WordPress TinyMCE wp_editor() 时如何设置占位符文本
【发布时间】:2013-12-18 22:45:36
【问题描述】:

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

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

我的代码目前是:

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

这会生成一个包含所有花里胡哨的文本区域,例如 TinyMCE 按钮和快速标签,但我看不到如何设置占位符文本。使用标准文本区域,您可以这样做:

<textarea name="content" placeholder="Write something"></textarea>

【问题讨论】:

    标签: php wordpress forms tinymce


    【解决方案1】:

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

    我认为通常你会使用 wp_content 传递它需要的所有点点滴滴,就像这样:

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

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

    所以我建议在调用wp_content() 函数之前,测试$content 是否为空,如果你发现确实是,那么你可以用占位符内容播种它:

    if( strlen( stripslashes($content)) == 0) $content = "Write something";
    wp_editor( stripslashes($content), $editor_id, $settings );
    

    【讨论】:

      猜你喜欢
      • 2013-12-18
      • 2016-04-08
      • 1970-01-01
      • 2017-11-25
      • 2021-11-30
      • 2011-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多