The upload_size_limit
hook in WordPress allows you to set a maximum file upload size for the Media Library. To increase this limit, follow these steps:
Example Code:
function increase_upload_size_limit($size) {
// Set the size in bytes, e.g., 50 MB (50 * 1024 * 1024)
$max_upload_size = 50 * 1024 * 1024;
// Return the new value
return $max_upload_size;
}
add_filter('upload_size_limit', 'increase_upload_size_limit');
Add the following code to the functions.php file of your theme or a custom plugin:
Explanation:
- $size: The current file size limit passed through the hook.
- $max_upload_size: The new size you want to set. In this example, it’s 50 MB.
- The function returns the modified value, and WordPress applies it as the new limit.
Additional Steps:
- PHP Settings: Ensure the PHP configuration does not impose a lower limit than what you set in the filter. Check or modify the following settings in your
php.ini
file:
upload_max_filesize = 50M
post_max_size = 50M
- .htaccess: If your server uses Apache, add this to your
.htaccess
file:
php_value upload_max_filesize 50M
php_value post_max_size 50M
- Server Configuration: Some hosting providers may have their own limits. You may need to adjust these via the hosting control panel or contact support.
After making these changes, test file uploads via the WordPress Media Library to ensure everything is working as expected.