用 WordPress TinyMCE wp_editor() 替换 textarea [英] Replacing a textarea with WordPress TinyMCE wp_editor()

查看:22
本文介绍了用 WordPress TinyMCE wp_editor() 替换 textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 wp_editor() 替换 textarea

我的 textarea 表单元素如下所示:

<textarea name="post_text" id="post_text" rows="3"><?php echo $content;?></textarea>

然后我有:

wp_editor( $content, 'post_text' );

我遇到的问题是表单 textarea 和 wp_editor textarea 都在页面上输出.为什么两个文本区域都显示?我只需要一个 textarea 来显示.一切都保存得很好,我只是有 2 个文本区域显示的问题.

是否像将 display: none; 放在表单的 textarea 上那么简单,以便只显示 wp_editor() textarea?这似乎有效,但感觉有点黑客.

解决方案

我找到了解决方案.您可以使用第三个参数来传递参数数组.现在这在 Codex 中已经很明显了:http://codex.wordpress.org/Function_Reference/wp_editor>

有点令人困惑(我的问题的根源)是 $editor_id 可能只包含小写字母.因此,如果您的表单处理脚本正在寻找带有下划线的内容(就像我的一样),那么您需要这样做:

$settings = array( 'textarea_name' => 'post_text' )wp_editor( $content, $editor_id, $settings );

请注意,您不能这样做:

wp_editor( $content, 'post_text' );

我哪里出错了.

I am trying to replace a textarea with wp_editor()

My textarea form element looks like this:

<textarea name="post_text" id="post_text" rows="3"><?php echo $content; ?></textarea>

Then I have:

wp_editor( $content, 'post_text' );

The problem I am getting is both the form textarea and the wp_editor textarea are outputted on the page. Why are both textareas displaying? I only need one textarea to display. Everything saves fine, I just have this problem of 2 textareas showing.

EDIT: Is it as simple as putting a display: none; on my form's textarea so just the wp_editor() textarea displays? That seems to work but feels a bit hackish.

解决方案

I found the solution. You can use a third parameter to pass an array of arguments. Now this is pretty obvious as outlined in the Codex: http://codex.wordpress.org/Function_Reference/wp_editor

What is a little confusing (the source of my problem) is $editor_id may only contain lowercase letters. So if your form processing script is looking for something with underscores in it (as mine was) then you'll need to do this:

$settings = array( 'textarea_name' => 'post_text' )

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

Note you can't do this:

wp_editor( $content, 'post_text' );

Which is where I went wrong.

这篇关于用 WordPress TinyMCE wp_editor() 替换 textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆