The “Allowed memory size exhausted” error means a PHP request asked for more memory than its limit allows, so PHP stopped the page. Raising the limit usually takes one line in wp-config.php. When that line seems to do nothing, the reason is almost always in how WordPress applies it, which is what most guides skip. This one walks through the core code that sets the limit, how to read the error, and what to do when the host has locked the value.
What does “allowed memory size exhausted” mean in WordPress?
It means one PHP request reached its memory_limit and PHP ended it with a fatal error. WordPress, a plugin or the theme tried to hold more data in memory than the limit allows. The page shows the error, a blank screen or a 500 response, depending on your debug settings.
A typical message looks like this:
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted
(tried to allocate 20480 bytes) in /wp-includes/class-wpdb.php on line 2349
The first number is the limit that was in force for that request. The second is the size of the single allocation that failed, which tells you little on its own. The file path shows what was running at the moment memory ran out, which may or may not be the code that used it up.
If the site shows a blank page instead of this message, turn on debug logging first. The white screen of death guide covers WP_DEBUG_LOG, and a memory error that returns a server error is covered in the 500 internal server error guide.
How do you read the bytes in the error message?
Divide the first number by 1,048,576 to get megabytes. PHP reports the limit in bytes, and one megabyte in PHP’s shorthand (the “M” in 256M) is 1,024 × 1,024 bytes. So 268435456 bytes is 256M, which tells you the request was already running with WordPress’s admin limit.
| Bytes in the error | Limit | Where that value usually comes from |
|---|---|---|
| 33554432 | 32M | An old or deliberately low host setting |
| 41943040 | 40M | WordPress’s single-site default for WP_MEMORY_LIMIT |
| 67108864 | 64M | WordPress’s multisite default, or a host setting |
| 134217728 | 128M | PHP’s own default memory_limit |
| 268435456 | 256M | WordPress’s default WP_MAX_MEMORY_LIMIT for admin screens |
| 536870912 | 512M | A value someone raised by hand |
Reading the number first saves guesswork. If the error says 128M and you already set WP_MEMORY_LIMIT to 256M, your setting never took effect, and the section on why it fails below applies. If it says 512M, raising it again probably won’t help and you should look for the cause.
What memory limit does WordPress use by default?
WordPress defines WP_MEMORY_LIMIT as 40M on a single site and 64M on multisite, and WP_MAX_MEMORY_LIMIT as 256M. It only ever raises PHP’s limit, never lowers it. Because PHP’s own default is 128M, the 40M value changes nothing on most servers.
The logic lives in wp_initial_constants() in wp-includes/default-constants.php:
if ( ! defined( 'WP_MEMORY_LIMIT' ) ) {
if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
define( 'WP_MEMORY_LIMIT', $current_limit );
} elseif ( is_multisite() ) {
define( 'WP_MEMORY_LIMIT', '64M' );
} else {
define( 'WP_MEMORY_LIMIT', '40M' );
}
}
// Set memory limits.
$wp_limit_int = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
if ( -1 !== $current_limit_int && ( -1 === $wp_limit_int || $wp_limit_int > $current_limit_int ) ) {
ini_set( 'memory_limit', WP_MEMORY_LIMIT );
}
Two details matter here. WordPress calls ini_set() only when your value is higher than the current one, and it does nothing when PHP’s limit is -1 (unlimited). The admin limit works the same way: WP_MAX_MEMORY_LIMIT defaults to 256M, or to the php.ini value if that is already higher.
The higher admin limit is applied later by wp_raise_memory_limit(), and only in specific places. With PHP’s default of 128M and no constants in wp-config.php, this is what each kind of request gets:
| Request | Limit in force | Why |
|---|---|---|
| Front-end page view | 128M | 40M is lower than PHP’s 128M, so WordPress leaves it alone |
| wp-admin as an Administrator | 256M | wp-admin/admin.php calls wp_raise_memory_limit( 'admin' ) for users who can manage_options |
| wp-admin as an Editor or Author | 128M | The admin raise is skipped for roles without manage_options |
| Image upload, resize or crop | 256M | The GD and Imagick editors call wp_raise_memory_limit( 'image' ) for any role |
| WP-Cron run | 256M | wp-cron.php calls wp_raise_memory_limit( 'cron' ) |
This explains a common report: the site crashes for an editor saving a long post but works for the admin doing the same thing. It also explains why background jobs can run fine while front-end pages fail. If scheduled tasks are the problem, see why WP-Cron stops running.
Developers can change each context with a filter: admin_memory_limit, image_memory_limit, cron_memory_limit (added in WordPress 6.3) or {$context}_memory_limit for a custom context.
How do you check your current memory limit?
Go to Tools → Site Health → Info in wp-admin. The Server section shows “PHP memory limit”, and the WordPress Constants section shows WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT. Compare these with the number in your error to see which limit the failing request actually hit.
Site Health runs inside wp-admin, where the admin raise has already happened. WordPress accounts for that: when the two values differ, the Server section shows two rows, “PHP memory limit” with the original value and “PHP memory limit (only for admin screens)” with the raised one. The front end runs with the first value. The Site Health documentation describes the Info tab and its copy-to-clipboard export, which is useful to send to a host.
Two other ways to check:
- With WP-CLI, run
wp eval 'echo ini_get( "memory_limit" ), " ", WP_MEMORY_LIMIT, " ", WP_MAX_MEMORY_LIMIT;'. The command line uses its own php.ini, so itsmemory_limitcan differ from the one your web server uses. - The free Query Monitor plugin shows peak memory use for each page load in the admin toolbar. That tells you how close normal pages run to the limit, which the error alone can’t.
Avoid leaving a public phpinfo() file on the server to check this. It exposes server paths and configuration to anyone who finds it.
How do you increase the WordPress memory limit?
Add WP_MEMORY_LIMIT and, if admin screens fail too, WP_MAX_MEMORY_LIMIT to wp-config.php above the “stop editing” line. WordPress then raises PHP’s limit for you. This works on most hosts. If Site Health doesn’t show the new value afterwards, set PHP’s own memory_limit instead.
- Read the limit from the error by dividing the bytes by 1,048,576, so you know which value you’re replacing.
- Check Tools → Site Health → Info and note the current “PHP memory limit” and
WP_MEMORY_LIMIT. - Open
wp-config.phpin the WordPress root over SFTP or your host’s file manager, and add this line above/* That's all, stop editing! Happy publishing. */:define( 'WP_MEMORY_LIMIT', '256M' );If the error happens in wp-admin, during image uploads or in cron jobs that already run at 256M, add
define( 'WP_MAX_MEMORY_LIMIT', '512M' );on the next line as well. - Reload Site Health. If “PHP memory limit” still shows the old value, set
memory_limitin.user.iniorphp.inias shown in the next sections, or ask your host to raise it. - Reload the page that failed. If the error returns at the new, higher number, find what is using the memory with Query Monitor and the debug log before raising it again.
The lines must sit above the require_once ABSPATH . 'wp-settings.php'; line at the end of the file. wp-settings.php is where wp_initial_constants() runs, so anything defined after it is ignored. The official wp-config.php documentation covers both constants.
Each place you can set the limit suits a different server setup:
| Method | Where | Works when | Takes effect |
|---|---|---|---|
WP_MEMORY_LIMIT |
wp-config.php |
The host allows ini_set() on memory_limit |
Next request |
.user.ini |
WordPress root | PHP runs as CGI/FastCGI, which includes PHP-FPM | Within 5 minutes by default |
php.ini |
Server PHP config | You have root access, for example on a VPS | After restarting PHP-FPM or Apache |
php_value |
.htaccess |
Apache with PHP loaded as an Apache module only | Next request |
| Hosting panel or support | Your host | Managed hosting where you can’t edit PHP config | Depends on the host |
Why didn’t WP_MEMORY_LIMIT change anything?
Usually because the host has locked PHP’s memory_limit, so WordPress’s ini_set() call is refused. It can also be a value lower than PHP’s current limit, a constant placed below wp-settings.php, or a request that uses the admin limit instead. Site Health shows which one applies.
Work through these in order:
- The value is lower than the current limit. WordPress only raises. Setting
WP_MEMORY_LIMITto 64M on a server already at 128M changes nothing, by design. - The line is in the wrong place. Constants defined below the
require_onceline forwp-settings.phpare read too late. - The failing request uses the other constant. Admin screens, image processing and cron use
WP_MAX_MEMORY_LIMIT, so raising onlyWP_MEMORY_LIMITwon’t help there. - The host locked the value. PHP’s manual says a setting applied with
php_admin_valuecannot be overridden by .htaccess or ini_set(). Some hosts also disableini_setentirely. - PHP 8.5 or later caps it. PHP 8.5 added a startup-only
max_memory_limitsetting. According to the PHP core ini documentation, amemory_limitabove it is capped with a warning.
The last two need a change at the PHP level, which the next section covers. If you can’t make it, ask the host which limit your plan allows.
How do you set memory_limit in .user.ini, php.ini or .htaccess?
Use .user.ini on most shared and managed hosts, because they run PHP-FPM. Use php.ini on a server you control. Use .htaccess only on Apache with PHP loaded as a module. All three set PHP’s own limit, which WP_MEMORY_LIMIT can then work within.
.user.ini (PHP-FPM and CGI)
Create or edit .user.ini in the WordPress root:
memory_limit = 256M
PHP reads these files only under the CGI/FastCGI SAPI. It caches them, so the default user_ini.cache_ttl of 300 seconds means a change can take up to five minutes to appear. Wait before deciding it didn’t work.
php.ini (VPS or dedicated server)
Find the file PHP-FPM actually loads with php-fpm8.3 -i | grep "Loaded Configuration" (adjust the version), set memory_limit = 256M, and restart the service, for example sudo systemctl restart php8.3-fpm. The command-line php.ini is a separate file, so editing it changes WP-CLI and not the website.
.htaccess (Apache module only)
php_value memory_limit 256M
This directive only exists when PHP runs as an Apache module. On the far more common PHP-FPM setup, Apache doesn’t recognise php_value and usually answers every request with a 500 error. If the site breaks after adding it, remove the line.
If you are still on an old PHP version, moving to a current one is worth doing at the same time. The guide to upgrading PHP on a WordPress site covers checking plugin compatibility first.
How much memory should a WordPress site have?
For most business sites, 256M is a sensible WP_MEMORY_LIMIT, and it matches WooCommerce’s published recommendation of a “WordPress memory limit of 256 MB or greater“. Pick the value from measured peak usage, because the limit applies to each PHP process separately.
The limit is a cap per request. Ten PHP workers each allowed 512M could in theory claim 5 GB together, so a very high limit on a small server shifts the failure from a PHP error to the server running out of RAM.
Use Query Monitor’s peak memory figure on your heaviest pages, such as checkout, a large product archive or the block editor with a long post. If normal peaks sit well under 128M and only one action fails, the problem is that action, and a higher limit only hides it. Avoid -1 (unlimited) on a live site for the same reason.
What if the error comes back after raising the limit?
Something is using memory abnormally, and raising the limit again only moves the failure point. Find the request that fails, then the plugin, query or file behind it. Query Monitor, the debug log and deactivating plugins one at a time on a staging copy will usually identify it.
Patterns that point to a cause:
- The error appears only on one screen, such as a report or an import. That plugin is loading too many records at once.
- The error started after an update. Roll back that plugin or theme on staging and test again.
- The limit in the error keeps rising with each fix you apply. That often means a loop or recursive hook, so more memory just delays it.
- The admin is slow as well as failing. The slow WordPress admin guide covers heavy dashboard widgets and admin-ajax calls.
To isolate a plugin safely, follow the steps in identifying and fixing plugin conflicts, and use the WordPress debugging documentation to log errors without showing them to visitors.


