How to Increase the WordPress Media Upload Limit: Two Effective Methods
As a WordPress user, you may have encountered the frustrating issue of the default media upload limit. This limitation can be especially problematic when you need to upload larger files, such as high-quality images, videos, or other media assets. Fortunately, there are two reliable methods you can use to increase the WordPress media upload limit and ensure your content can be seamlessly added to your website.
Method 1: Modify the PHP.ini and .htaccess Files
The first method involves directly editing the PHP.ini and .htaccess files to adjust the upload size and execution time limits.
Step A: Modify the theme's functions.php file
- Open your WordPress website's dashboard and navigate to the "Appearance" section.
- Click on the "Editor" option, and then select the "functions.php" file from the list of theme files.
- Add the following code to the end of the file:
@ini_set( 'upload_max_size' , '64M' );
@ini_set( 'post_max_size', '64M');
@ini_set( 'max_execution_time', '300' );
This code snippet increases the upload size limit to 64MB and the maximum execution time to 300 seconds (5 minutes). If 64MB doesn't work for your needs, you can try a different value, such as 10MB.
Step B: Create or Edit an Existing PHP.INI File
- Locate the PHP.INI file on your server. This file is typically located in the root directory of your WordPress installation or in the server's main configuration folder.
- Open the PHP.INI file in a text editor and add the following lines:
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
These settings will apply the same file size and execution time limits as the code added in Step A.
Step C: Edit the .htaccess File
- In your WordPress website's root folder, locate the .htaccess file.
- Open the .htaccess file in a text editor and add the following lines:
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
These directives in the .htaccess file will also increase the media upload limit and execution time.
Method 2: Use the wp_handle_upload_prefilter
Hook
The second method involves using a custom WordPress function that leverages the wp_handle_upload_prefilter
hook to check the file size and prevent the upload if it exceeds a specific limit.
- Open your WordPress website's dashboard and navigate to the "Plugins" section.
- Click on the "Add New" button and search for a plugin called "Code Snippets" or a similar plugin that allows you to add custom code to your WordPress site.
- Install and activate the plugin.
- In the WordPress admin menu, go to "Appearance" > "Code Snippets" (or the equivalent section in your chosen plugin).
- Create a new code snippet and add the following code:
function limit_upload_size( $file ) {
// Set the desired file size limit in KB
$file_size_limit = 1024; // 1MB in KB
// Exclude administrators from the file size limit
if ( ! current_user_can( 'manage_options' ) ) {
$current_size = $file['size'];
$current_size = $current_size / 1024; // Get size in KB
if ( $current_size > $file_size_limit ) {
$file['error'] = sprintf( __( 'ERROR: File size limit is %d KB.' ), $file_size_limit );
}
}
return $file;
}
add_filter( 'wp_handle_upload_prefilter', 'limit_upload_size', 10, 1 );
This code snippet sets a file size limit of 1MB (1024 KB) and applies it to all users except administrators. If a user tries to upload a file larger than the limit, the upload will be blocked, and an error message will be displayed.
You can adjust the $file_size_limit
variable to set a different file size limit, depending on your needs.
Both of these methods are proven to be effective in increasing the WordPress media upload limit. The first method, which involves modifying the PHP.INI and .htaccess files, provides a more global solution and applies the changes to the entire WordPress installation. The second method, using the wp_handle_upload_prefilter
hook, offers a more granular approach and allows you to set different file size limits for different user roles.
Whichever method you choose, remember to test the changes thoroughly to ensure they are working as expected and that your website is still functioning correctly. Additionally, it's important to note that increasing the upload limit may have implications on your server's performance and storage capacity, so be mindful of these factors and adjust the limits accordingly.
By implementing these solutions, you can overcome the default WordPress media upload limit and seamlessly incorporate larger files into your website, enhancing the overall user experience and content quality.
Flowpoint.ai can help you identify all the technical errors that are impacting conversion rates on your WordPress website and directly generate recommendations to fix them, including optimizing your media upload limits.