Skip Navigation

[Resolved] Image field & SVG

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 8 replies, has 3 voices.

Last updated by rahulS-5 7 years ago.

Assigned support staff: emerson.

Author
Posts
#245343

Hi, i'm using SVG in image field but i cant save the custom post type because SVG "are not recognize as image"

See the attachment...

Do you have a workaround?

#245668

Dear Patrice,
You need to add a filter in your active theme functions.php to enable the uploading and saving of SVG. Take a look at the example here:
https://toolset.com/forums/topic/how-to-enable-svg-output-support-in-views/#post-228344

You need to add this code:
[php]
function cc_mime_types( $mimes ){
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );
[/php]

This will allow you to upload SVG. If you are having issues with displaying the SVG with Types or Views, take a look at the succeeding post of this thread: https://toolset.com/forums/topic/how-to-enable-svg-output-support-in-views/#post-228344 (read each of the post below). Then it should give a lot of information pertaining to fixing the display issues with SVG.
Please let me know how it goes. Thanks 🙂

Cheers,
Emerson

#247086

It was working before i update to wordpress 4...

I have this in my function and it not working now...

function cc_mime_types( $mimes ){
    $mimes['svg'] = 'image/svg+xml';
    return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );
#247350

Dear Patrice,
OK, I test that filter to see if there are new changes added on WordPress 4.0. I'll update here later on 🙂

Cheers,
Emerson

#247357

Dear Patrice,
I confirmed this to be a limitation of Types unable to recognize SVG as an image. I'll check this with our developers for immediate patch. Thanks 🙂

Cheers,
Emerson

#247358

Dear Patrice,
You can fix this temporarily by going to the Types plugin and editing this file: /embedded/common/toolset-forms/classes/class.image.php
Edit the addTypeValidation to this one (take note I've added svg as one of the extensions, so Types plugin can recognize this):

    public static function addTypeValidation($validation) {
        $validation['extension'] = array(
            'args' => array(
                'extension',
                'jpg|jpeg|gif|png|bmp|svg|webp',
            ),
            'message' => __( 'You can add only images.', 'wpv-views' ),
        );
        return $validation;
    } 

Of course, do this only if you urgently need this feature to work. Otherwise , it would be advisable to wait for a fix from the Types plugin developers so you won't need to edit any core files from Types. Please let me know how it goes. Thanks.

Cheers,
Emerson

#247663

Dear Patrice,
We just send you the development version of Types that contains the support for SVG. Please test it in your dev site and confirm it is now fixed. Thanks 🙂

Cheers,
Emerson

#247750

It's fixed.

Thanks

#390483

How do I enable it now? Because the folders you have mentioned don't exist in the plugin folder anymore. How do I get svg working now?

Because it still just displays the link directly.

Please help