Archived topic
Local Font Use Of OTF File
6 replies · Started by Michelle on April 14, 2022
I am trying to upload a local font into my Media Library use via Code Snippets, and get a message saying "this file type is not allowed". Is there a php snippet that would allow me to upload an .otf? Converting my font to a .ttf may be more difficult since it is a custom ancient font I made.
Here is the code I am using, which is clearly for a .ttf
add_filter( 'upload_mimes', function( $mimes ) {
$mimes['woff'] = 'application/x-font-woff';
$mimes['woff2'] = 'application/x-font-woff2';
$mimes['ttf'] = 'application/x-font-ttf';
$mimes['svg'] = 'image/svg+xml';
$mimes['eot'] = 'application/vnd.ms-fontobject';
return $mimes;
} );
I tried to make it work by adding this line after the 'ttf' line, but it did not work:
$mimes['otf'] = 'application/x-font-otf';
Hi Michelle,
Can you give this line a try ? $mimes['otf'] = 'font/otf';
Sure. I just added this to my wp-config:
define('ALLOW_UNFILTERED_UPLOADS', true);
It still didn't work. I will give your code a try now.
It still won't allow me to upload the file. It is a working font file. I have it installed in WORD
You can also try these 2 lines:
$existing_mimes['otf'] = 'application/font-sfnt';
$existing_mimes['otf'] = 'application/otf';
But adding define('ALLOW_UNFILTERED_UPLOADS', true); to wp-config.php should work.
If it still doesn't work, it's better reach out to WP's support as theme doesn't have the control over this.
I was able to get the fonts uploaded by modifying my wp-config. Thank you.
No problem :)