Home › Forums › General Issues › SVG code getting stripped out of field › Reply To: SVG code getting stripped out of field
I ran into the same issue with ACF text area fields used to hold SVG code for menu icons. Each time I would enter the SVG code, it would not save. From the link posted by John above, I came up with the following (added to functions.php) which resolved my issue. I still get security notices from Wordfence – but the SVG code can now be saved.
/**
* ACF SVG filter to allow raw SVG code.
*
* https://www.advancedcustomfields.com/resources/html-escaping/
*
*/
add_filter( 'wp_kses_allowed_html', 'acf_add_allowed_svg_tag', 10, 2 );
function acf_add_allowed_svg_tag( $tags, $context ) {
if ( $context === 'acf' ) {
$tags['svg'] = array(
'xmlns' => true,
'width' => true,
'height' => true,
'preserveAspectRatio' => true,
'fill' => true,
'viewbox' => true,
'role' => true,
'aria-hidden' => true,
'focusable' => true,
);
$tags['path'] = array(
'd' => true,
'fill' => true,
);
}
return $tags;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.