我想在wordpress编辑器(v3.3+)中插入一些短代码
字符串看起来像
[a_col]<p>some text or other stuff</p>[/a_col]
这很好,但如果我在JS 中使用这行
tinyMCE.get('content').setContent(string);
我的短代码被p标签包围,看起来像
<p>[a_col]</p><p>some text or other stuff</p><p>[/a_col]</p>
我真的不喜欢接触原生函数。也许有一种不同的解决方案来插入内容
如果要在"the_content"上添加_filter,您可能会解析出
标签:
http://codex.wordpress.org/Function_Reference/add_filter
在"编辑器"中从tinymce模式切换到HTML模式。这样就不会转换文本字段中的内容。
这是我的解决方案:
shortcode函数返回
<div class="col a">'.preg_replace('#^</p>|<p>$#', '', do_shortcode($content)).'</div>
这将删除所有不需要的p标签
这个问题在Wordpress 2.5.1版本中修复,请参阅快捷代码API了解更多详细信息
<?php remove_filter ('the_content', 'wpautop'); ?>
http://codex.wordpress.org/Function_Reference/remove_filter