How to Enable Font File Uploads in WordPress?

Typography plays a crucial role in creating a visually appealing website. Recently, I encountered a challenge while trying to upload a font file, specifically Calibre-Light.woff, to my WordPress website. WordPress, by default, restricts certain file types for security reasons. In this tutorial, I will share my personal experience and guide you through the steps I took to successfully enable font file uploads in WordPress.

I wanted more control over how the font integrated into my website. So, to enable font file upload, I add below code snippets to my WordPress theme’s functions.php file.

// Allow additional font file types to be uploaded
function custom_allow_font_uploads($mime_types) {
    $mime_types['woff'] = 'font/woff';
    $mime_types['woff2'] = 'font/woff2';
    return $mime_types;
add_filter('upload_mimes', 'custom_allow_font_uploads');

This code adds the .woff and .woff2 font file extensions to the list of allowed MIME types for uploads. Once I’ve added this code, I able to upload font files using the WordPress media uploader.

Please note that modifying the functions.php file of WordPress theme should be done with caution, and it’s recommended to have a backup of your theme files before making any changes.

Leave a Reply