WordPress允许用户留言img标签的方法

追格_咖小啡/ 01月04日/ WordPress/ 浏览 345

WordPress访客留言img标签后会自动被过滤,其实这是WordPress基于安全策略考虑,也就是说非管理员权限是无法在留言中插入图片。


想解决上述问题其实也很简单,我们可以通过给wp_kses_allowed_html添加过滤器来增加img标签。


示例代码:


// Create function which allows more tags within comments
function crunchify_allowed_html_tags() {
    return array(
        'a' => array(
            'href' => true,
            'title' => true,
        ),
        'br' => array(),
        'em' => array(),
        'strong' => array(),
        'pre' => array(),
        'p' => array(),
        'code' => array(),
    );
}
add_filter( 'wp_kses_allowed_html', 'crunchify_allowed_html_tags', 1 );

发表评论

暂无评论,抢个沙发...

客服 工单