escaping - How to keep specific tag from an html string?

Hello I try to keep only specific tag from an html string.For example:$allowed_tag=array('a');$content = 

Hello I try to keep only specific tag from an html string.

For example:

$allowed_tag=array('a');
$content = '<a href="#">link</a> <b>strong text</b>';
$content = prefix_remove_specific_tag($content, $allowed_tag);
echo $content

Will return

<a href="#">link</a> strong text

I'm sure a wp core function existe for that, but i can't find it :(

Hello I try to keep only specific tag from an html string.

For example:

$allowed_tag=array('a');
$content = '<a href="#">link</a> <b>strong text</b>';
$content = prefix_remove_specific_tag($content, $allowed_tag);
echo $content

Will return

<a href="#">link</a> strong text

I'm sure a wp core function existe for that, but i can't find it :(

Share Improve this question edited Oct 16, 2019 at 8:05 ZecKa asked Oct 16, 2019 at 6:59 ZecKaZecKa 7781 gold badge6 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I had to ask to finally find the solution, lol.

The wp_kses do exactly that:

$allowed_tags = array(
    'a'      => array(
        'href'      => array(),
    ),
);
$content = '<a href="#">link</a> <b>strong text</b>';
$content = wp_kses($content, $allowed_tags);

I found the solution in another topic

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745077156a4609904.html

相关推荐

  • escaping - How to keep specific tag from an html string?

    Hello I try to keep only specific tag from an html string.For example:$allowed_tag=array('a');$content = 

    15小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信