最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论