【问题标题】:Wordpress custom content area with wp editor?带有 wp 编辑器的 Wordpress 自定义内容区域?
【发布时间】:2016-01-05 10:19:28
【问题描述】:

使用我的 Wordpress 主题函数文件,我创建了一个自定义元文本区域(请参见下面的屏幕截图)。

编辑页面时显示自定义元文本区域。

保存和更改文本效果很好,但是如果我将段落文本的某个部分更改为标题 2 并单击保存,它会将标题 2 恢复为段落。

我的函数更新后元框如下所示:

if( isset( $_POST['my_meta_box_text_challengetbl'] ) )
    update_post_meta( $post_id, 'my_meta_box_text_challengetbl', wp_kses( $_POST['my_meta_box_text_challengetbl'], $allowed ) );
}

$allowed php 代码如下所示:

$allowed = array( 
    'a' => array( // on allow a tags
        'href' => array() // and those anchords can only have href attribute
    )
);

【问题讨论】:

  • 能否请您让我们看看 $allowed 的值是什么,需要包含“h2”等
  • 嗨,西蒙,没问题,请参阅上面修改的我的问题,其值为 $allowed。

标签: php wordpress


【解决方案1】:

请更新...

$allowed = array( 
    'a' => array( // on allow a tags
        'href' => array() // and those anchords can only have href attribute
    ),
    'h2' => array()
);

这将允许使用 H2,注意:您也可以在此处添加您希望允许的任何其他 html 标签。查看https://codex.wordpress.org/Function_Reference/wp_kses 了解更多信息。

【讨论】:

  • 太棒了,非常感谢您的回答,这很有效。我只允许添加锚标签,如上所述,我添加了完美运行的 h2 标签。
  • 好东西 :) 很高兴能为您提供帮助,就像我说的,请查看链接以了解如何在需要时添加更多标签。
猜你喜欢
  • 2013-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-16
相关资源
最近更新 更多