• Tevya

    (@thefiddler)


    Hi, I’m trying to upload an animated logo for my site, but it seems to be changing the file slightly and removing some data from it, thus breaking the animation. I have previously-uploaded animated SVG’s that were not broken by uploading.

    Is it possible that a recent update broke this? Could you fix it?

Viewing 1 replies (of 1 total)
  • Super-late response, but: Safe SVG makes use of the Enshrined SVG Sanitizer, which has a list of allowed tags & attributes. If you are animating your SVG with native SMIL (Synchronized Multimedia Integration Language) with tags like animate, they will get stripped out by default. Fortunately, it’s pretty easy to deal with, as Safe SVG adds filters for these.

    In your theme’s functions.php, add the following code:

    function allow_safe_svg_animation($array) {
    	$array[] = 'animate';
    
    	return $array;
    }
    
    add_filter('svg_allowed_tags', 'allow_safe_svg_animation', 10, 1);
    add_filter('svg_allowed_attributes', 'allow_safe_svg_animation', 10, 1);

    All this does is add the animate tag to the allowable list of SVG tags that now _won’t_ get stripped out. (I also added the svg_allowed_attributes filter in there too, as the format & return are identical).

Viewing 1 replies (of 1 total)
  • The topic ‘Breaking animation in animated SVG’s’ is closed to new replies.