How to increase the maximum file size allowed for uploading via WordPress Media Library on the upload_size_limit hook?

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:

  1. $size: The current file size limit passed through the hook.
  2. $max_upload_size: The new size you want to set. In this example, it’s 50 MB.
  3. 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.

How useful is the publication?

Click on a star to rate it!

Average score 5 / 5. Number of grades: 1

No ratings yet. Rate it first.

Similar posts

How to transfer a site from dle to WordPress?

Transferring a website from DLE (DataLife Engine) to WordPress can be a complex process, especially if the site has a lot of content. Here’s a step-by-step guide: 1. Preparation 2. Export Data from DLE DLE uses its own database structure, so you’ll need to export data and convert it into a format compatible with WordPress:…
Read more