Skip Navigation

[Resolved] Custom Field File upload, allow certain file types to upload

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 1 reply, has 2 voices.

Last updated by Christian Cox 1 year, 6 months ago.

Assigned support staff: Christian Cox.

Author
Posts
#1235558

Hello

A simple question. I'm adding a custom field to a CPT to upload a file.
The file that needed to be uploaded are KML/KMZ files. Maps coordination files to show on top of Google Maps.

But I dont see any possibility to allow upload of those files.

I am missing something or how to do?

Regards,
Kristof

#1235728

Christian Cox
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Hi, the default is based on WordPress's allowed mime types:
https://codex.wordpress.org/Function_Reference/get_allowed_mime_types

You can use the upload_mimes hook to add more mime types:
https://developer.wordpress.org/reference/hooks/upload_mimes/
Example:

function my_custom_mime_types( $mimes ) {
     
    // New allowed mime types.
    $mimes['svg']  = 'image/svg+xml';
    $mimes['svgz'] = 'image/svg+xml';
    $mimes['doc']  = 'application/msword'; 
 
    // Optional. Remove a mime type.
    unset( $mimes['exe'] );
 
    return $mimes;
}
 
add_filter( 'upload_mimes', 'my_custom_mime_types' );

You can add the custom code to your child theme's functions.php file, or create a new custom code snippet in Toolset > Settings > Custom code. I'm not sure what the mime type definitions would be for those types of files, but you should be able to find out by searching Google.