2

How do I decrease my media file size upload limit from 20 MB to 500 KB? I actually tried to follow the solution used in Decrease file size upload in Media but got a "undefined add_filter()" error. I inserted the code at the bottom of functions.php.

Using WP 3.5.1

What should I do? Thank you

6
  • 1
    Please add more info. Where do you put the code? In functions.php? – Roman Jun 7 '13 at 6:37
  • Yes in functions.php at the very bottom – rabbid Jun 7 '13 at 7:45
  • the error indicates that you are not using the functions.php in your current theme directory, is that the case? – birgire Jun 7 '13 at 8:28
  • @birgire ah yes that is true... I pasted it in the original functions.php. What is the correct way to do this? – rabbid Jun 7 '13 at 8:32
  • 1
    the path should be like this: /wp-content/themes/your-theme-name/functions.php or better yet, change this code into a plugin, see more about it here codex.wordpress.org/Writing_a_Plugin – birgire Jun 7 '13 at 9:18
4

The answer to this questions depends on the level of access you have to your server. Shared hosts often limit the options you have. Your options are:

1) Changing a directive in your php.ini: Heres how to find it.

This will change the setting for all websites using php on this server. Many shared hosts don't allow this.

Find the line in that says upload_max_filesize and edit it to look like the following:

upload_max_filesize = 500K

2.a) Setting an ini directive in the .htaccess file (if you use apache):

In the .htaccess file in the WordPress root directory (where the wp-config.php file is) add the following on a new line:

php_value upload_max_filesize 500K

This will change the setting for that installation of WordPress only.

Be aware, many shared hosts will not allow this. Additionally this will only work if you are using PHP as an apache module and AllowOverride is set to "Options" or "All" more info here.

2.b) With a .user.ini file:

Much like .htaccess above, a .user.ini file is used to override directives at a directory level. This will only work if your server is using the CGI/FastCGI SAPI. So if you're on Azure App Service/IIS or something similar this is probably what you want.

Syntax is: upload_max_filesize = 500K

3) Changing the directive in WordPress with ini_set():

This should work on a shared host.

Add the following line to your functions.php:

ini_set( 'upload_max_size' , '500K' );

This works by changing the setting every time this file is run. functions.php is run on every load when the theme is active so this effectively changes the limit when using your theme.

Bonus: WordPress Multisite

Navigate to Network Admin > Settings > Network Settings. You should see the setting close to the bottom of the page. However, the maximum limit you can set here is dictated by the other PHP settings outlined in the this answer.

1
  • 1) Changing a directive in your php.ini worked for me – Pathros May 18 '18 at 16:37
0

You can use this code inside of the functions.php file to in case or decrease the upload size. You can also increase the size by changing 2M to more.

@ini_set('upload_max_size', '500K');
@ini_set('post_max_size', '500K');
@ini_set('max_execution_time', '300');
1
  • Making post_max_size that small will most likely mess other stuff up like the saving of menus and posts. The max max_execution_time wouldn't need to be changed for this question either. I wouldn't change post_max_size or max_execution_time unless there is a reason to. – DaveLak May 28 '17 at 2:52
-1

I am using the plugin WP Image Size Limit. It works about 80% the way I like.

A couple of things I don't like:

  1. In the Upload Media view still says 20 MB is the limit.
  2. Looks like it does the size check AFTER the upload is done, instead of before. Seems inefficient to me.
1
  • plugins are rarely good answers..., this was unmaintained for a while – Mark Kaplun Oct 7 '17 at 5:21
-1

First Method

You can add this in your functions.php file :

@ini_set( 'upload_max_size' , '500K' );
@ini_set( 'post_max_size', '500K');
@ini_set( 'max_execution_time', '100' );

Second Method

Add this in your .htaccess file :

php_value upload_max_filesize 500K
php_value post_max_size 500K
php_value max_execution_time 100
php_value max_input_time 100

Thirs Method

Add this in your php.ini file :

upload_max_filesize = 500K
post_max_size = 500K
max_execution_time = 100
1
  • Not sure why everyone thinks changing the post_max_size and max_execution_time setting are necessary. Making post_max_size so low will likely cause issues with menus/posts/pages saving, especially when using a menu builder plugin. The issue may not be evident immediately but as the site grows so does the risk of conflict. – DaveLak May 28 '17 at 1:43
-2

put this into your .htaccess file

php_value upload_max_filesize 500K
php_value post_max_size 500K
php_value max_execution_time 100
php_value max_input_time 100
1
  • 2
    Please add an explanation to your answer: why could that solve the problem? – fuxia Jun 7 '13 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.