WordPress Memory Limit Errors What They Mean and How to Fix Them

WordPress Memory Limit Errors What They Mean and How to Fix Them

WordPress memory limit errors mean PHP has hit the memory_limit directive while executing a request, and the fix is almost always to raise that limit in wp-config.php. The error appears as Allowed memory size of X bytes exhausted in your logs or on screen, and it happens when a plugin, theme, or core operation tries to allocate more memory than the current limit allows. You can fix it safely by editing one file, but you need to understand what the limit is, why it is being hit, and how to change it without masking a deeper problem.

What the memory limit actually is

PHP runs each HTTP request in a single process, and the memory_limit directive sets the maximum number of bytes that process can use before PHP throws a fatal error. The default value is often 128M on shared hosting, but it can be as low as 32M on older configurations or as high as 256M on managed setups. WordPress itself is fairly lean, but a page load can involve loading the core, all active plugins, the active theme, and the database result set for that request. A single plugin with a poorly written query can easily consume tens of megabytes, and a page builder or a caching plugin that builds a large in-memory object can push you over the limit.

When the limit is exceeded, PHP aborts the request and writes a fatal error to the error log. The message includes the exact number of bytes allowed and the file and line where the allocation failed, which is useful for debugging. The key thing to know is that the limit is per request, not per site, so a single heavy page can trigger the error even if the rest of your site is fine.

How to find the current limit and the error

Before you change anything, confirm what the current limit is and where the error is coming from. You can check the limit from the command line if you have SSH access, or you can create a temporary PHP file that calls phpinfo(). The command line approach is cleaner because it does not leave a file on your server. Run this from your WordPress root directory:

php -r "echo ini_get('memory_limit'), PHP_EOL;"

The output will look like 128M or 256M. That is the value PHP uses for CLI scripts, which may differ from the value used for web requests. To see the web value, you need to check the PHP-FPM or Apache configuration, or you can look at the error log for the exact number in the fatal error message. If you do not have SSH access, create a file called phpinfo.php in your web root with this content:

<?php phpinfo(); ?>

Load that file in your browser, find the memory_limit row under the Core section, then delete the file immediately. Leaving a phpinfo() file on a public server is a security risk because it exposes your full configuration.

Raising the limit in wp-config.php

The safest and most portable way to increase the limit is to add a single line to wp-config.php. This file is loaded on every request, and the value you set there overrides the server default for WordPress only, not for other PHP scripts on the same server. Open wp-config.php in a text editor and look for the line that says /* That's all, stop editing! Happy publishing. */. Add this line just above it:

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

That sets the limit to 256 megabytes for all WordPress requests. If you run a multisite network, you can also set WP_MAX_MEMORY_LIMIT for admin pages, but for a single site the WP_MEMORY_LIMIT constant is enough. Save the file and reload the page that was failing. If the error is gone, you are done. If it still appears, the limit you set is being overridden by something else, usually a server-level php.ini directive that uses php_admin_value, which cannot be overridden from a script. In that case you need to edit php.ini or the PHP-FPM pool configuration directly, or contact your host to raise the limit for you.

One common mistake is to set the value without the unit. PHP accepts 256M, 256K, or a plain integer which is interpreted as bytes. If you write define('WP_MEMORY_LIMIT', 256); you are setting 256 bytes, which will break your site instantly. Always include the M suffix for megabytes.

Why raising the limit is not always the right fix

Increasing the memory limit treats the symptom, not the cause. If a single plugin is leaking memory or running an unbounded query, raising the limit from 128M to 256M will only delay the failure. The right approach is to identify what is consuming the memory. Look at the fatal error message in your log. It will include the file and line where the allocation failed, which often points to a specific plugin. Disable that plugin temporarily and see if the error goes away. If it does, you have found the culprit. You can then decide whether to replace the plugin, update it, or contact its developer with the exact error message.

Another cause is a theme that loads too many assets or runs heavy image processing on every page. A poorly optimized image gallery can build a large array of image metadata in memory. Check your theme settings for lazy loading and image size options. Also check your object cache. If you use a caching plugin that stores full page objects in memory, a large cache can push you over the limit. Clearing the cache often resolves the error immediately, which is a good diagnostic step before you edit any files.

WordPress memory limit error fix: a step by step approach

Here is the order of operations you should follow when you see the error. First, read the full error message from your log. Note the byte count and the file path. Second, check the current limit with the command above or with phpinfo(). Third, add the WP_MEMORY_LIMIT constant to wp-config.php and test. Fourth, if the error persists, disable all plugins by renaming the wp-content/plugins directory to wp-content/plugins.off and test again. If the error goes away, re-enable plugins one by one to find the offender. Fifth, if the error persists with all plugins off, switch to a default theme by renaming your active theme directory and test. This isolates the problem to either a plugin or a theme.

If you have SSH access, you can also check the actual memory usage of a request using the memory_get_peak_usage() function in a test script, but that requires modifying a file and is overkill for most cases. The plugin and theme isolation method is faster and safer.

What to do next

After you have raised the limit and confirmed the error is gone, do not stop there. Monitor your error log for the next few days to see if the same error returns. If it does, the underlying problem is a plugin or theme that is genuinely consuming too much memory, and you should replace it rather than keep raising the limit. Also check whether your hosting plan has a hard memory ceiling. If you are on shared hosting and the server itself caps PHP memory at 256M, no constant in wp-config.php will push past that. In that case, the practical fix is to reduce the memory footprint of your site, not to increase the limit. Start by removing unused plugins, enabling a page cache, and ensuring your images are compressed. Those changes will lower peak memory usage and make the error a rare event rather than a recurring one.

Related articles

Subscribe to our newsletter

Get the latest hosting tips, performance insights, and industry news.