Wordpress自定义内容区域与wp编辑器?

3

通过我的WordPress主题函数文件,我已经创建了一个自定义的元数据文本区域(请参见下面的屏幕截图)。

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

enter image description here

它可以很好地保存和更改文本,但如果我将段落文本的某个部分更改为标题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
    )
);

2
请问您能让我们看到$allowed的值吗?它需要包含"h2"等内容。 - Simon Pollard
嗨,西蒙,没问题,请看我修改后的问题,其中包括$allowed的值。 - Craig
1个回答

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标签,它完美地工作了。 - Craig
太棒了 :) 很高兴能帮忙,就像我说的,如果需要更多标签,请查看链接。 - Simon Pollard

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接