Skip to content

Instantly share code, notes, and snippets.

@jamesdixon
Created March 9, 2015 21:54
Show Gist options
  • Save jamesdixon/8ee2f09557d4e2bd7c09 to your computer and use it in GitHub Desktop.
Save jamesdixon/8ee2f09557d4e2bd7c09 to your computer and use it in GitHub Desktop.
Wordpress Allow Custom Font Upload
<?php
// add to your theme's functions.php file
add_filter('upload_mimes', 'add_custom_upload_mimes');
function add_custom_upload_mimes($existing_mimes) {
$existing_mimes['otf'] = 'application/x-font-otf';
$existing_mimes['woff'] = 'application/x-font-woff';
$existing_mimes['ttf'] = 'application/x-font-ttf';
$existing_mimes['svg'] = 'image/svg+xml';
$existing_mimes['eot'] = 'application/vnd.ms-fontobject';
return $existing_mimes;
}
?>
@ghonchesefidi
Copy link

Great. worked out

@ahmedghazi
Copy link

doesn't work for otf :(

@Kalabybis
Copy link

neither does ttf for some reason... the function is being called and the ttf is in list

@wellingtonpragidi
Copy link

perfect

@muhammad-salman09
Copy link

not working for .ttf

@artemhorbenko
Copy link

not working for .ttf

@olivierstern
Copy link

olivierstern commented Feb 12, 2019

for ttf it depends of your server. You can get it like this :

mime_content_type ( 'path/to/some/file.ttf' );

or even

$existing_mimes['ttf'] =  mime_content_type ( get_stylesheet_directory().'/src/fonts/examplefont.ttf' );

@rulyardiansyah
Copy link

Just wanna say thank you...
It works for me.

@pierrehenri220
Copy link

@olivierstern awesome, on my current host it was "application/font-sfnt" !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment