Increase WordPress PHP max input variables

The PHP max input variables (or max_input_vars value) is the maximum number of variables your server can use for a single function. To work correctly with modern WordPress themes, we recommend setting this value to 3000. If the setting is too low, you may experience problems such as lost data and disappearing widgets.

Check your PHP Version

Before modifying anything, it's useful to check what version of PHP you're using. Older versions, such as 5.x, are often the default used by shared hosts for compatibility reasons. They might also limit max_input_vars to around 1000, even if you specify a higher value using the steps described in this article.

To check your version of PHP, from the WordPress Dashboard:

  1. Select Tools > Site Health.
  2. Click the Info tab.
  3. Scroll down to Server and click to expand.
  4. Look for the value PHP version.

Reputable shared hosts will let you modify the PHP version yourself within their administrative control panel. We recommend using PHP Version 7.3 or higher for modern WordPress themes.

How to increase PHP max input variables

Method 1: Edit the php.ini file

Many shared hosts prohibit you from having direct access to the php.ini file. Only use this procedure if you can access the file, otherwise, skip to the next method.

  1. Locate the php.ini file. Search your web host’s knowledge base for php.ini and you should come up with where to find it.
  2. Open the file and locate the line of code that reads max_input_vars = N, where N represents the numeric value currently specified.
  3. Set the value to your desired limit, for example, max_input_vars = 3000;.
  4. Save the file and exit.

Method 2: Edit the .htaccess file

  1. Locate the .htacess file. This is normally stored in the root folder of your WordPress installation. If you can't locate it, it might be because it is hidden. Most text editors have a menu option to Show hidden files or Hide invisible files, or similar- the exact location and label of the menu item will differ depending on the application you're using, so consult your software vendor's documentation for more information.
  2. Open the .htacess file.
  3. Add the code php_value max_input_vars 3000 on a new line following the code # END WordPress. If you add the code before # END WordPress your WordPress installation may overwrite it.
  4. Save the file and exit.

Verify the new PHP max input variables

Once you have modified max_input_vars to the new value, you can confirm the change from the WordPress Dashboard:

  1. Select Tools > Site Health.
  2. Click the Info tab.
  3. Scroll down to Server and click to expand.
  4. Look for the heading PHP max input variables. The figure here should now match the new value.

Increase WordPress memory limit

Sometimes when trying to perform an action in WordPress, such as activating a plugin, you might get an error that looks like this:

Fatal error: Allowed memory size of 987654321 bytes exhausted (tried to allocate 12345 bytes)

If you're running resource-intensive plugins or themes, there may come a time when you find yourself hitting this error. Basically, it just means that the server needed more memory to perform the task than was allocated. The error specifically relates to memory for PHP, which is the language that WordPress runs on. The solution is to increase the amount of memory allocated to PHP.

Understanding WordPress memory allocation

Before you go changing your PHP memory allocation, it's really important to understand two key points.

Firstly, there is memory allocation for PHP, then there is an allocation of how much of that PHP memory can be used by WordPress. If your server is solely dedicated to hosting a WordPress website, then typically these values would be the same. However, you can allocate less PHP memory to WordPress specifically if you were running other PHP applications on your server. WordPress memory can only be increased while it is less than the PHP memory allocation - otherwise increasing the WordPress memory limit will do nothing.

The second thing to understand is that both the PHP and WordPress memory allocations don't refer to total memory, but rather the amount of memory allocated per script that is run. If multiple scripts are running, then the memory allocated will be multiplied by the number of scripts. This means that specifying a larger-than-necessary memory allocation may cause your server to run out of memory. In this case, more is not necessarily better - just enough to ensure the task no longer triggers a memory exhausted error is best.

How to increase the WordPress PHP memory limit

If you're using a hosting service, changes to these files should take effect immediately. If you're running your own server, you'll need to restart both PHP and the web server for changes to take effect, or you can reboot.

php.ini

Let's look at increasing the PHP memory limit first, since WordPress can't allocate more memory than is specified here. Depending on your host, you may or may not have access to this file, and you may or may not be able to create your own. Search your web host's knowledge base for php.ini and you should come up with where to locate the file.

Once you've located the file, it's simply a case of adding the following line (or editing the existing one if it is already specified). In this example, we're allocating 128MB of memory.

memory_limit = 128M

.htaccess

If you don’t have access to your php.ini file, sometimes you can use your .htaccess file to set the memory limit:

php_value memory_limit 128M

wp-config.php

Now that we've increased the PHP memory limit, we can specify how much of that memory is allocated for use by WordPress. The default memory allocated to WordPress is 32MB but we can increase that by editing the wp-config.php file located in the root folder of your WordPress installation. If you have WooCommerce installed, they recommend a memory limit of 64MB, some complex themes will require a limit of 96MB and most websites shouldn't need more than 128MB. The best approach is to increase the limit incrementally until the error goes away.

Locate the line of text that reads /* That's all, stop editing! Happy publishing. */ and place the following code just above that line. In this example, we're allocating memory of 128MB.

define('WP_MEMORY_LIMIT', '128M');

The WordPress Dashboard is more memory intensive than your website, so it may be that it's just the WordPress administration area than needs more memory rather than your website. You can allocate memory for the WordPress administration area using the following code. This can be specified in addition to the example above and should always be a higher value. Here we're allocating 256MB memory for WordPress administration, but remember that your PHP memory needs to be the same or higher than this value for it to work.

define('WP_MAX_MEMORY_LIMIT', '256M');

If you've been experimenting with getting the correct memory allocation to resolve a memory exhausted error, you may need to go back and amend the memory limit in the php.ini file. If your server is used solely for your WordPress website, then the PHP memory allocation and the WordPress memory allocation should be the same.


Remove dates from WordPress URLs

By default, WordPress organises media files, like images, into folders based on the year and month the file was uploaded. This can cause issues later on if you need to update files, so it's a good idea to decide on the URL structure for media before you start building your website.

The WordPress dashboard contains the settings that control month- and year-based folders. To remove dates from URLs in your WordPress media file uploads:

  1. Go to the WordPress Dashboard
  2. Choose Settings > Media
  3. Disable the checkbox next to Organise my uploads into month- and year-based folders
  4. Choose Save Changes.

Existing files won't change retrospectively. Media is only affected when it is uploaded — and they stay that way.

Pros and Cons

Search Engine Optimisation

From an SEO perspective, there’s no real benefit to using dates within your URLs. Excluding dates will make each URL shorter and improve readability. Shorter URLs are considered more favourably for search engine optimisation and websites that adopt a good URL architecture with concise and meaningful URLs perform better.

Using dates in URLs also means larger HTML page sizes and skews the text-to-HTML ratio, both of which are SEO factors. Even though this is a relatively minor issue, you should always keep your code as concise and efficient as possible for performance reasons — the use of dates in media URLs is simply unnecessary.

Website performance

If you have a large WordPress website that uses a lot of files, then saving media into different URLs may have advantages. Every operating system has its limitations and performance degradation based on the number of files that exist in a single directory. Locating the correct file takes more time as the number of files grows. Using multiple folders to store media files can improve website performance in this scenario.

When we talk about performance degradation in WordPress, we generally mean tens of thousands of files per folder. The majority of WordPress sites don’t publish that number of files, so performance won't be a concern. Even if you have a large number of media files, you should consider serving these through a dedicated storage service and CDN to shift the load away from your web server.

We can help with website performance if you're experiencing issues with your WordPress website.

Website maintenance

One of the main issues with using dates in URLs is that it can create extra work with updating static content on your WordPress website. These include logos, Open Graph images, images linked in email templates, backlinks to media from other websites and so on. With date URLs active, updating media will also change the media URL, and that means breaking the file path for anything that relies on it. The exception is where the change is made in the same year and month as the original media, the filename is the same and provided the original media is deleted before uploading the replacement. If not, you'll need to update every system that points to the media to keep things intact, and that can be a nuisance.

Recommendations

Enable Media Replace plugin

The Enable Media Replace plugin by ShortPixel can be a real time saver. It allows you to replace existing media files in WordPress without changing the URL. The plugin integrates directly with the WordPress Media Library and is compatible with major caching plugins like WP Rocket and image optimisation plugins like Short Pixel Image Optimiser.

Mixed settings

A feature of the Organise my uploads into month- and year-based folders option in WordPress is that it only applies as media is uploaded. This provides a level of control that enables you to deal with static media, such as logos, differently from other media content.

When first building your website, upload common static media with the setting disabled so they won't save to a dated folder. For all other media, you can upload with the setting enabled. If you need to update media that doesn't have a date URL, disable the setting again before you add the replacement.