Can’t extract and set SVG dimensions

I solved it!!! The filter in fix #3 (above) wasn’t working because of the third condition of this if statement that triggers the dimension extraction and attachment: if (is_array($image) && preg_match(‘/\.svg$/i’, $image[0]) && $image[1] == 1) $image[1] in the third condition is the reported width of the SVG file as WP sees it before it … Read more

How to upload SVG in WordPress 4.9.8?

This question had me scratching my head. Yeah, how come WordPress doesn’t support this natively? And then I found out. You asked how to upload SVG in WordPress 4.9.8 (the current version at the time of writing). You mention that you “tried uploading after installing different plugins”. You don’t say which plugins, nor whether they … Read more

Escaping and sanitizing SVGs in metabox textarea

Here is a PHP library that was created for sanitizing SVG files that may be worth looking into. https://github.com/darylldoyle/svg-sanitizer Here is an example of how this could be used: // Now do what you want with your clean SVG/XML data function your_save_meta( $post_id, $post, $update ) { // – Update the post’s metadata. if ( … Read more

Ways to handle SVG rendering in wordpress?

Take a look at wp_prepare_attachment_for_js(), which is what gathers attachment metadata for use on the Media pages. The eponymous filter lets us add or alter metadata. The following example can be dropped into functions.php. Note: this requires SimpleXML support in PHP. function common_svg_media_thumbnails($response, $attachment, $meta){ if($response[‘type’] === ‘image’ && $response[‘subtype’] === ‘svg+xml’ && class_exists(‘SimpleXMLElement’)) { … Read more

SVG files not uploading since most recent WP update

In WordPress 4.7.1 a change was introduced that checks for the real mime type of an uploaded file. This breaks uploading file types like SVG or DOCX. There already exist tickets for this issue in WordPress Core, where you can read more about this: Some Non-image files fail to upload after 4.7.1 (https://core.trac.wordpress.org/ticket/39550) SVG upload … Read more

Batch command for ImageMagick to convert all files in a directory and sub-directories on windows

Try with a FOR loop with /R flag from inside your root folder: this command will convert all the .svg files in your sub-directories under the root folder you launched your command from. Above command works for command line, if you plan to use the command inside a batch file (.bat) remember to use %% … Read more