Created
June 27, 2023 10:03
-
-
Save dkesberg/088a13b0bc20881b2e5b5016d32b9b2f to your computer and use it in GitHub Desktop.
WP Sanitize SVG markup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sanitize SVG markup for front-end display. | |
* | |
* @link https://developer.wordpress.org/reference/functions/wp_kses/#comment-6185 | |
* | |
* @param string $svg SVG markup to sanitize. | |
* @return string Sanitized markup. | |
*/ | |
function sanitize_svg( $svg = '' ) { | |
$allowed_html = array( | |
'svg' => array( | |
'xmlns' => array(), | |
'fill' => array(), | |
'viewbox' => array(), | |
'role' => array(), | |
'aria-hidden' => array(), | |
'focusable' => array(), | |
'height' => array(), | |
'width' => array(), | |
), | |
'path' => array( | |
'd' => array(), | |
'fill' => array(), | |
), | |
); | |
return wp_kses( $svg, $allowed_html ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment