Limit Maximum Size of Uploaded Files in WordPress Easily

How to increase maximum file upload size in wordpress; Wordpress increase upload file size limit; Change wordpress upload size limit; Increase file upload limit wordpress; Wordpress max upload size limit; How to change upload size in wordpress; Wordpress upload file size too large; Increase wordpress media upload size; Wordpress file upload size limit; How to upload large files in wordpress;

Explanation

If you're looking to upload larger files to your WordPress site, you can adjust the maximum file size limit with a bit of code. Here's how it works:

Adjusting Upload Size Limits:

  • The code sets the maximum file upload size to 64MB. This means you can upload files up to this size without any issues.
  • It also adjusts the maximum time allowed for uploads to 5 minutes, which helps prevent timeouts during larger uploads.

How It Works:

  • The first function modifies WordPress's internal settings to allow larger uploads.
  • The second function changes the server's PHP settings to match, ensuring everything works smoothly.

Remember, these changes need to be supported by your server's configuration. If your server doesn't allow these limits, you might need to contact your hosting provider for assistance.

Code

<?php
/**
 * Increase the maximum file upload size in WordPress.
 *
 * This function modifies the upload size limit for media files.
 * It is important to ensure that your server settings also allow for the increased limits.
 *
 * @param array $sizes An array of upload size limits.
 * @return array Modified array of upload size limits.
 */
function wp_dudecom_increase_upload_size_limit( $sizes ) {
    // Set the maximum upload size to 64MB.
    $sizes['upload_max_size'] = 64 * 1024 * 1024; // 64MB in bytes
    $sizes['post_max_size'] = 64 * 1024 * 1024; // 64MB in bytes
    $sizes['max_execution_time'] = 300; // 5 minutes

    return $sizes;
}
add_filter( 'upload_size_limit', 'wp_dudecom_increase_upload_size_limit' );

/**
 * Modify the server settings for upload size.
 *
 * This function sets the PHP ini settings for upload size limits.
 */
function wp_dudecom_modify_php_ini_settings() {
    @ini_set( 'upload_max_filesize', '64M' );
    @ini_set( 'post_max_size', '64M' );
    @ini_set( 'max_execution_time', '300' );
}
add_action( 'init', 'wp_dudecom_modify_php_ini_settings' );
?>

Instructions

File Location: Add the code to your theme's functions.php file or a custom plugin file.

Prerequisites:

  • Ensure you have access to your WordPress theme files or the ability to create a custom plugin.
  • Verify that your server settings can accommodate the increased upload limits. Contact your hosting provider if unsure.

Implementation Steps:

  1. Log in to your WordPress admin dashboard.
  2. Navigate to Appearance > Theme Editor if you are editing the functions.php file, or go to Plugins > Editor if you are using a custom plugin.
  3. Locate the functions.php file in the right-hand sidebar if editing a theme, or open your custom plugin file.
  4. Copy and paste the provided code snippet into the file.
  5. Save the changes to the file.
  6. Test the upload functionality by attempting to upload a file up to 64MB in size to ensure the changes have taken effect.

If you encounter any issues or need further assistance, consider reaching out to wp-dude.com for professional help with implementation or more advanced WordPress functionality.