在我搜索答案时发现了您的问题。我试着用wp\\U kses做了更多的实验,发现下面的外壳viewbox
在争论中似乎解决了这个问题。您不必以小写形式将实际属性放在SVG上,只需wp_kses()
论点
这可能超出您的需要,但我现在使用的是:
<?php
$kses_defaults = wp_kses_allowed_html( \'post\' );
$svg_args = array(
\'svg\' => array(
\'class\' => true,
\'aria-hidden\' => true,
\'aria-labelledby\' => true,
\'role\' => true,
\'xmlns\' => true,
\'width\' => true,
\'height\' => true,
\'viewbox\' => true, // <= Must be lower case!
),
\'g\' => array( \'fill\' => true ),
\'title\' => array( \'title\' => true ),
\'path\' => array( \'d\' => true, \'fill\' => true, ),
);
$allowed_tags = array_merge( $kses_defaults, $svg_args );
echo wp_kses( $rich_text_that_might_include_SVGs, $allowed_tags );