Adding custom font failed

I have woff and otf font.

I have tried many things.

  1. I added

    function font_mime_types($mimes) {
    $mimes[‘svg’] = ‘image/svg+xml’;
    $mimes[‘woff’] = ‘font/woff’;
    $mimes[‘otf’] = ‘font/otf’;
    $mimes[‘woff2’] = ‘font/woff2’;
    return $mimes;
    }
    add_filter(‘upload_mimes’, ‘font_mime_types’);

  2. I uploaded fonts to uploads folder

  3. Tried to add custom font trough wordpress plugin.

Nothing worked so font enters into font editor, and when I try to upload trough media gallery I get that file type is not allowed.

What can I do to change this?
I can change something on the server, if there is the problem. Just tell me what to look for, please :smiley:

thank you

Hello Cybill,

Thanks for writing in!

Please update your code and see if this works:

add_filter('upload_mimes', 'add_custom_upload_mimes');
function add_custom_upload_mimes($existing_mimes) {
	$existing_mimes['otf'] = 'application/x-font-otf';
	$existing_mimes['ttf'] = 'application/x-font-ttf';
	$existing_mimes['eot'] = 'application/vnd.ms-fontobject';
        $existing_mimes['woff'] = 'font/woff';
        $existing_mimes['woff2'] = 'font/woff2';
	return $existing_mimes;
}

For the meantime, you can installAdd From Server plugin and upload your fonts using through that, then head back to Font Manager and import the font (by opening the media library pop up), but instead of uploading, just select the already uploaded fonts through that plugin.

Hope this helps. Please let us know how it goes.

It worked with add from server
but I had to convert the fonts into Woff

Hello Cybill,

.woff should should be okay and if the preferred font format to be uploaded.

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.