How do I allow a single Wordpress site to accept my .ttf file upload?
Asked Answered
A

4

10

I'm using the Font Organizer plugin for Wordpress. It has a nice option to upload a font, which I have saved to my computer. I just need to somehow get Wordpress to accept it so I can use it here:

enter image description here

However, I'm getting an error: Error uploading the file: Sorry, this file type is not permitted for security reasons.

How do I let Wordpress temporarily allow this? Also, is this method even going to work out? The end goal is for it to show up on the drop down list in the image above because I need to change the font of the header text. I can do any programming stuff needed.

Akela answered 16/1, 2017 at 0:22 Comment(0)
F
10

Unfortunately for me neither the code snippet for functions.php or the plugin worked.

I had to temporarily add the following code to wp-config.php:

define('ALLOW_UNFILTERED_UPLOADS', true);

And then of course deleted it as soon as I had uploaded the font.

(However in future I will attempt to use compressed font versions as suggested in the bottom two answers).

Finegrain answered 10/3, 2020 at 3:46 Comment(0)
T
7

You can allow uploading the .ttf font on your site, by adding a simple filter code on function.php file.

Below is the code for .ttf font only

    add_filter('upload_mimes', 'add_custom_upload_mimes');
    function add_custom_upload_mimes($existing_mimes) {
        $existing_mimes['ttf'] = 'application/x-font-ttf';
        return $existing_mimes;
   }

You can add more MIME type in the function to allow to upload those file.

Tullis answered 21/6, 2017 at 10:31 Comment(2)
This does not work for me. I can allow another file types this way (svg, otf), but ttf - application/x-font-ttf is ignored by wordpress. Don't you know why?Feints
For anyone else this didn't work for see this post to force MIME type detection for TTF file extension: wordpress.stackexchange.com/questions/396325/…Jos
E
3

There is plugins that allow you to whitelist certain mime types.

Also the add_filter hook can be used to extend the default allowed mime types from a theme or plugin.

P.S.: You really shouldn't use ttf for web use, since it's uncompressed. Use woff, woff2 or eot instead.

Everglades answered 16/1, 2017 at 8:59 Comment(0)
S
3

You can use a code snippet to add support for certain mime types, or use a plugin to enable that feature. Or you could avoid the issue at all by converting the file to a compressed version, for example using an online converter like https://everythingfonts.com/ttf-to-woff

This was the first one I run into while trying to solve your very same problem; it's not the best or the fastest or anything: it just works.

Skipbomb answered 10/1, 2018 at 16:58 Comment(4)
And..why the downvote? What's wrong, what could be enhanced?Skipbomb
Certainly got my upvote, great tip re the online converter!Finegrain
In my WordPress, woff font's are not allowed to ...Jule
Yes @MarcoFloriano you usually can upload a woff font via a Theme or a plugin that allows it for theming purposes. Wordpress on its own does not allow it :-)Skipbomb

© 2022 - 2024 — McMap. All rights reserved.