Allow TTF Uploads WordPress

User
Raleway-Italic-VariableFont_wght.ttf
Sorry, you are not allowed to upload this file type.
in wordpress admin media
Assistant
The error message "Sorry, you are not allowed to upload this file type" in WordPress is usually due to the site's MIME types not allowing the file type you are trying to upload. By default, WordPress does not allow uploading of font files like `.ttf`.

To allow the upload of `.ttf` files (or any other file types), you can add a filter to your theme's `functions.php` file. Here’s how you can do it:

1. **Edit your theme's `functions.php` file:**
– Go to your WordPress admin panel.
– Navigate to **Appearance** > **Theme Editor**.
– Select the `functions.php` file from the right-hand side.

2. **Add the following code:**

function custom_upload_mimes($mimes) {
       $mimes['ttf'] = 'font/ttf';
       return $mimes;
   }
   add_filter('upload_mimes', 'custom_upload_mimes');

3. **Save the changes.**

This code snippet adds the MIME type for `.ttf` files, allowing you to upload them through the media library.

After adding this code, try uploading the Raleway font file again. If you still face issues, ensure that your WordPress installation and theme do not have additional restrictions on file uploads.

User
above not working
Assistant
If adding the MIME type for `.ttf` files to your `functions.php` file did not resolve the issue, here are a few additional steps you can take to troubleshoot and allow the upload of `.ttf` files in WordPress:

### 1. Check File Permissions
Make sure that the permissions for the `wp-content/uploads` directory are set correctly. The recommended permissions are usually `755` for directories and `644` for files. You can check and modify permissions via your FTP client or your hosting control panel.

### 2. Modify the `.htaccess` File
If you're using Apache, you can try adding the following line to your `.htaccess` file in the root directory of your WordPress installation:

AddType font/ttf .ttf

### 3. Check for Security Plugins
Some security plugins (like Wordfence or Sucuri) may block certain file types. Check your security plugin settings to see if there are any restrictions on file uploads and adjust them accordingly.

### 4. Use a Plugin to Allow Font Uploads
If the above methods do not work, consider using a plugin to manage MIME types. One popular plugin is **WP Add Mime Types**. Here’s how to use it:

1. **Install and Activate the Plugin:**
– Go to **Plugins** > **Add New**.
– Search for "WP Add Mime Types".
– Install and activate the plugin.

2. **Configure MIME Types:**
– After activation, go to **Settings** > **Mime Type Settings**.
– Add the following entry:

ttf = application/x-font-ttf

– Save your changes.

### 5. Clear Cache
If you're using any caching plugins or server-side caching (like Varnish), clear the cache after making these changes.

### 6. Try Uploading Again
After making these changes, try uploading your `.ttf` file again through the WordPress media library.

### 7. Check PHP Settings
Lastly, ensure that your server's PHP settings allow for file uploads. You may need to check the `php.ini` file for the following settings:

– `file_uploads = On`
– `upload_max_filesize` (make sure this is set high enough)

If you are on shared hosting and do not have access to the `php.ini` file, you may need to contact your hosting provider for assistance.

Try these methods, and let me know if you encounter any issues!

User
# Start: Block all search engine bots from accessing the site – (Do not Edit)

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|baiduspider|yandex|duckduckbot) [NC]
RewriteRule .* – [F,L]

Header set X-Robots-Tag "noindex, nofollow"

# End: Block all search engine bots from accessing the site – (Do not Edit)

# AuthUserFile /home/cmimri/public_html/.htpasswd
# AuthName "Please Log In"
# AuthType Basic
# require user cmimri

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.

RewriteEngine On
RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress
# php — BEGIN cPanel-generated handler, do not edit
# Set the “ea-php81” package as the default “PHP” programming language.

AddHandler application/x-httpd-ea-php81 .php .php8 .phtml

# php — END cPanel-generated handler, do not edit
add in above

Assistant
To allow the upload of `.ttf` font files in your WordPress site, you can add the `AddType` directive to your `.htaccess` file. Based on the existing structure of your `.htaccess` file, you can insert the new directive within the appropriate section. Here’s how you can do it:

1. **Open your `.htaccess` file:**
You can do this via your WordPress admin panel (using a file editor plugin), through FTP, or via your hosting provider’s file manager.

2. **Add the `AddType` directive:**
Place the following line right before the `# BEGIN WordPress` comment or at the end of the file, right before the closing tags:

AddType application/x-font-ttf .ttf

3. **Your modified `.htaccess` should look like this:**

# Start: Block all search engine bots from accessing the site - (Do not Edit)
   <IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|baiduspider|yandex|duckduckbot) [NC]
   RewriteRule .* - [F,L]
   </IfModule>

   <IfModule mod_headers.c>
       Header set X-Robots-Tag "noindex, nofollow"
   </IfModule>
   # End: Block all search engine bots from accessing the site - (Do not Edit)

   # AuthUserFile /home/cmimri/public_html/.htpasswd
   # AuthName "Please Log In"
   # AuthType Basic
   # require user cmimri

   AddType application/x-font-ttf .ttf

   # BEGIN WordPress
   # The directives (lines) between "BEGIN WordPress" and "END WordPress" are
   # dynamically generated, and should only be modified via WordPress filters.
   # Any changes to the directives between these markers will be overwritten.
   <IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
   RewriteBase /
   RewriteRule ^index.php$ - [L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule . /index.php [L]
   </IfModule>

   # END WordPress
   # php -- BEGIN cPanel-generated handler, do not edit
   # Set the “ea-php81” package as the default “PHP” programming language.
   <IfModule mime_module>
     AddHandler application/x-httpd-ea-php81 .php .php8 .phtml
   </IfModule>
   # php -- END cPanel-generated handler, do not edit

4. **Save the file** and then try to upload your `.ttf` file again in the WordPress media library.

### Additional Steps
– If the issue persists, make sure to clear any caches you may have, either through caching plugins or server-side caching.
– After making these changes, test the upload again.

Let me know if you encounter any issues!

Leave a Comment

Your email address will not be published. Required fields are marked *