Sanitize SVG Icon HTML in WordPress

Function:

<?php
function sanitize_svg_icon($svg_html) {
    return wp_kses($svg_html, array(
        'svg' => array(
            'fill' => true,
            'viewBox' => true,
            'xmlns' => true,
            'id' => true,
            'title' => true,
            'path' => array(
                'd' => true,
            ),
        ),
        'g' => array(
            'id' => true,
            'stroke-width' => true,
            'stroke-linecap' => true,
            'stroke-linejoin' => true,
        ),
    ));
}

$svg_open = sanitize_svg_icon('SVG html supply here');

Leave a Reply

Your email address will not be published. Required fields are marked *