Increase upload file size by wordpress filter

In most of time we are facing uploading issues for larger files because of its size limits. In previous article I have covered all 6 ways to increase this limits by using php.ini, .htaccess, config.php and cPanel configurations. You can checkout that article from here. But we have one more option to increase this upload size limit within your WordPress site.

WordPress provided one filter for this, with the help of this filter we can increase upload limits.

We have to just create one function and then we have to hook it to the filter provided by WordPress that is : upload_size_limit. In this function we will just calculate our required size and return it from function so it will take reflect by filter when it’s executes by wordpress.

In you WordPress active theme or child theme, just look for functions.php file and edit it. Then just copy/paste below code at end of the file and save it and its done.

/**
 * Upload size limit change by WordPress Filter
 *
 * @param string $upload_size Upload size limit (in bytes).
 * @return int (maybe) Filtered size limit.
 */
function modify_upload_size_limit_by_filter( $upload_size ) {
  // Set upload size limit to 800 MB as per user capabilities by checking 'manage_options' capability.
    if (!current_user_can('manage_options')) {
        // 800 MB.
        $upload_size = 800 * 1024 * 1024;
    }
    return $upload_size;
}
add_filter('upload_size_limit', 'modify_upload_size_limit_by_filter', 20);

So by this way, we can increase upload file size limits by WordPress provided filter. Above example code fromĀ Drew Jaynes. If it helps to you then please share it with other.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.