gpt4 book ai didi

wordpress -

缺少 wp_editor( get_option() );

转载 作者:行者123 更新时间:2023-12-01 19:19:17 25 4
gpt4 key购买 nike

我正在尝试向我的主题添加一些选项,并且添加了一个所见即所得文本区域,该文本区域的值将转到选项表(wp-options)。

这是我使用的代码:

$settings = array(
'textarea_name' => 'options[content]',
'quicktags' => true,
'tinymce'=> true,
);
wp_editor( get_option('content','default_value'), 'content', $settings );

这工作得很好,但这显然删除了所有 <p>内容中的标签,我完全不知道为什么..

例如,当我写下这样的内容时:

Level 1 title
Level 2 title
a paragraph
another paragraph

这是发送到名为“content”的数据库的代码:

<h1>Level 1 title</h1>
<h2>Level 2 title</h2>
a paragraph another paragraph

而不是这个:

<h1>Level 1 title</h1>
<h2>Level 2 title</h2>
<p>a paragraph</p>
<p>another paragraph</p>

你知道我可以做什么来让所有标签获得不变的值吗?

ps:当我添加<p>时手动将标签标记到文本侧,直到我返回到视觉侧并重新保存为止。

感谢您的帮助

最佳答案

我知道这是一个老问题,已经有一段时间得到了接受的答案,但答案对我不起作用,所以我添加了解决方案,以防它对其他人有帮助。

我应该解释一下,我的问题略有不同,因为它是在插件的管理设置页面中,而不是在主题中,但原理应该是相同的。也就是说,在这两种情况下,wp_editor 的输出都需要存储在选项中,然后使用完整的段落标签进行检索。

我的解决方案基于 Codex description of the wp_editor并涉及将 wpautop 作为参数添加到 wp_editor 调用。有点违反直觉,需要将其设置为 false 才能自动添加段落标签。然而,最初对 wpautop 的调用也需要在管理页面中包含段落标签。

$args = array(
'wpautop' => false
);
wp_editor( wpautop( $content ), $editor_id, $args );

关于wordpress - <p></p> 缺少 wp_editor( get_option() );,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27508157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com