You must control the files that users upload to your WordPress site for both security and simplicity. Controlling uploads helps stop unsafe programs, reduce risks, and maintain site compatibility. This guide provides a straightforward way to manage and control file types uploaded to your site.
Understanding the importance of limiting file uploads in WordPress is crucial. By default, WordPress allows images, document files, audio files, and video files to be uploaded. Although convenient, this flexibility might pose risks if not managed correctly.
By default, WordPress supports these file types:
If your website doesn’t need some of these, consider restricting them.
There are several methods to restrict file types, depending on your technical expertise and project needs.
Always create a full backup before making any changes to your WordPress site—especially when altering core behavior or installing new features. Backups protect your data and ensure you can restore your site if anything goes wrong. Consider using plugins like:
List the file types you want users to upload, which may vary by site type:
Having this list ready makes configurations clearer and more focused.
upload_mimes
Filter in functions.php
The most direct way to limit file types is by using the upload_mimes
filter in your theme’s functions.php
file.
How to do it:
functions.php
.What this does:
Overrides the default list of allowed file types and sets a custom list.
If you’re not comfortable editing theme files, plugins offer an easier method. Popular choices include:
You might allow certain file types for admins while restricting them for contributors or subscribers. This ensures sensitive or risky formats, like executable files, are kept away from general users. Meanwhile, it allows admins to manage these file types as needed, balancing security and functionality.
.htaccess
for Server-Level RestrictionsOn Apache-based servers, the .htaccess
file can add an extra restriction layer:
<FilesMatch "\.(exe|php|sh|bat|pl)$">
Order Deny,Allow
Deny from all
</FilesMatch>
This prevents access to potentially dangerous file types, even if they’re uploaded.
After setting restrictions:
Testing ensures your site functions as expected with user-defined rules.
Plugins like Wordfence or Sucuri Security can scan uploads for malware or anomalies.
Control file sizes using php.ini
or .htaccess
:
upload_max_filesize = 2M
post_max_size = 3M
Prevent file conflicts or attacks using plugins like “Media File Renamer” to rename files upon upload.
Never allow scripts or executables (e.g., .php, .exe) to be uploaded—even by admins.
File uploads can be convenient, but prioritizing security is essential to avoid issues. By following this guide, you can restrict file uploads effectively and address common concerns. Keeping your software updated and reviewing your site’s security settings regularly will further secure your website and its users. Thank you for reading our guide on restricting file uploads in WordPress. We hope it helps you manage your website’s security effectively.