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
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.
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.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:
First Method
You can add this in your functions.php file :
Second Method
Add this in your .htaccess file :
Thirs Method
Add this in your php.ini file :
put this into your .htaccess file