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

admin2025-04-19  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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745077157a283637.html

最新回复(0)