To increase the WordPress memory limit, add define( 'WP_MEMORY_LIMIT', '256M' ); to your wp-config.php file, above the “That’s all, stop editing!” line. WordPress then raises PHP’s memory_limit to 256 MB on every request. If the value doesn’t change, your host has locked PHP’s memory setting, and you need to raise it in php.ini, .user.ini or your hosting panel instead.
You’re probably here because of an error like this one in your logs, or the “There has been a critical error on this website” screen in front of it:
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 12288 bytes) in /sites/smartwp.co/wp-includes/plugin.php on line 584
Below: how WordPress actually decides its memory limit (it’s not 32 MB, and it never lowers the limit), five ways to raise it, how to check the value that’s really in effect, what the byte number in that error means, and when more memory is the wrong fix. I tested the constants on WordPress 7.1.4 with PHP 8.3 in WordPress Playground.
How WordPress sets its memory limit
WordPress defines two constants early in every request, in wp_initial_constants() inside wp-includes/default-constants.php:
| Constant | Default | Used for |
|---|---|---|
WP_MEMORY_LIMIT | 40M (64M on multisite) | Every request: front end, REST API, admin-ajax.php |
WP_MAX_MEMORY_LIMIT | 256M, or your PHP limit if that is higher | Admin screens for administrators, updates, image processing, WP-Cron |
WordPress only ever raises the limit, never lowers it. It calls ini_set( 'memory_limit', WP_MEMORY_LIMIT ) only when your constant is bigger than PHP’s current memory_limit. PHP’s own default is 128M, and most hosts set 256M or more, so the 40M default does nothing on almost every site. In my Playground test, PHP was set to 256M and WordPress reported WP_MEMORY_LIMIT as 40M while the real limit stayed at 256M. Defining 128M changed nothing either.
So the old advice that “the default WordPress memory limit is 32 MB” is wrong twice: the default is 40M, and it’s a floor WordPress tries to reach, not a cap.
The admin, image and cron contexts
For heavier work, WordPress calls wp_raise_memory_limit(), which bumps PHP up to WP_MAX_MEMORY_LIMIT. In WordPress 7.1 that happens in these places:
- Any wp-admin screen loaded by a user who can
manage_options(the'admin'context) - Unzipping plugin, theme and core update packages, and the image editor screen (also
'admin') - Loading an image into GD or Imagick to resize or crop it (the
'image'context). When this step fails during an upload, WordPress shows the “Suggested maximum size is 2560 pixels” error, and our image scaling guide explains what that upload error means. - Running
wp-cron.php(the'cron'context, added in WordPress 6.3)
Each context has a filter: admin_memory_limit, image_memory_limit and cron_memory_limit. Requests to admin-ajax.php and the REST API don’t go through wp-admin/admin.php, so they don’t get the admin bump. A page builder that saves over AJAX or REST runs at WP_MEMORY_LIMIT, which is why “it only crashes when I hit Save” is a common memory complaint.
If you only need more memory for big image uploads, the filter is more targeted than raising the global limit. This is the snippet I tested; with it, wp_raise_memory_limit( 'image' ) returned 512M and PHP’s limit moved to 512M:
add_filter( 'image_memory_limit', function () {
return '512M';
} );
Method 1: Increase the PHP memory limit in wp-config.php
This is the method to try first. Open wp-config.php in the root of your WordPress install (over SFTP, your host’s file manager, or SSH) and add these lines above the “That’s all, stop editing! Happy publishing.” comment:
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' ); // optional: admin, updates, images
Placement matters. Anything after the require_once ABSPATH . 'wp-settings.php'; line runs too late, because wp-settings.php is what defines the defaults. A constant can only be defined once, so search the file for an existing WP_MEMORY_LIMIT line before adding another.
Two things I confirmed in Playground with PHP at 256M:
- Setting
WP_MEMORY_LIMITto 512M raised PHP’s livememory_limitto 512M, above the php.ini value. A php.ini value is not a hard ceiling as long as the host allows runtime changes. - Because the new value was above 256M,
WP_MAX_MEMORY_LIMITfollowed it to 512M automatically. Core does this so the admin limit is never lower than the front-end one.
If you use WP-CLI, wp config set WP_MEMORY_LIMIT 256M writes the same line for you.
Method 2: Increase the PHP memory limit in php.ini
If WordPress can’t change the limit, set it where PHP reads it. On a VPS or dedicated server, edit the memory_limit line in the php.ini your web server uses:
memory_limit = 256M
Then restart PHP-FPM (for example sudo systemctl restart php8.3-fpm, matching your version) or Apache if PHP runs as a module. Not sure which file is loaded? phpinfo() shows “Loaded Configuration File”. Run it from a browser request, not the command line, because the CLI often loads a different php.ini.
Method 3: Use a .user.ini file (PHP-FPM and CGI hosting)
Most shared and managed hosts run PHP-FPM, where you can’t touch php.ini but can drop a .user.ini file in your site root:
memory_limit = 256M
Per the PHP manual, these files are only read by the CGI/FastCGI SAPI, and PHP rescans them every 300 seconds by default (user_ini.cache_ttl). If nothing changes right away, wait five minutes before assuming it failed.
Method 4: Increase the PHP memory limit using .htaccess
On Apache with PHP running as an Apache module (mod_php) or on LiteSpeed, you can set it in your site’s .htaccess file:
php_value memory_limit 256M
On Nginx this file is ignored, and on Apache with PHP-FPM the php_value line usually causes a 500 Internal Server Error. If your site goes down after adding it, remove the line and use .user.ini instead.
Method 5: Ask your host or use the hosting panel
Many hosts expose the PHP memory limit in their control panel (cPanel’s MultiPHP INI Editor, Plesk’s PHP Settings, or a per-site PHP screen on managed hosts). That’s the cleanest option when it exists, because it sets the real PHP-FPM value.
If none of the methods above change the number, ask your host. The usual cause is a pool set with php_admin_value[memory_limit]. The PHP manual says a value set with php_admin_value “can not be overridden by .htaccess or ini_set()”, and WordPress detects this with wp_is_ini_value_changeable() and stops trying. Some plans also cap memory per account, so ask what the maximum is.
How to check your current memory limit
Don’t trust the constant alone. Go to Tools > Site Health > Info and check two sections:
- Server: “PHP memory limit” is the real PHP value. When an admin screen raised it, you’ll also see “PHP memory limit (only for admin screens)”.
- WordPress Constants: the values of
WP_MEMORY_LIMITandWP_MAX_MEMORY_LIMIT.
Because you’re viewing Site Health in the admin as an administrator, the second line shows the raised admin value. The “PHP memory limit” line is the one front-end visitors get.
With WP-CLI:
wp eval 'echo WP_MEMORY_LIMIT . PHP_EOL;'
wp eval 'echo ini_get( "memory_limit" ) . PHP_EOL;'
Keep in mind WP-CLI runs on PHP’s command-line binary, which can load a different php.ini than your web server (php --ini shows which). For the value web requests actually get, Site Health or a quick ini_get( 'memory_limit' ) check loaded in the browser is more reliable.
What “Allowed memory size of X bytes exhausted” means
The first number is the memory limit that was in effect when PHP died, in bytes. The “tried to allocate” number is just the size of the one allocation that pushed it over, not how much more you need. Convert the first number to find out which limit you actually hit:
| Bytes in the error | Limit | Usually means |
|---|---|---|
| 33554432 | 32M | Very old host default |
| 41943040 | 40M | WordPress’s WP_MEMORY_LIMIT default applied |
| 67108864 | 64M | Multisite default, or a low host setting |
| 134217728 | 128M | PHP’s built-in default |
| 268435456 | 256M | WP_MAX_MEMORY_LIMIT default, or a common host setting |
| 536870912 | 512M | Already raised; look for a leak |
| 1073741824 | 1G | Something is almost certainly looping |
In Playground with WP_MEMORY_LIMIT at 512M, a deliberate runaway loop logged “Allowed memory size of 536870912 bytes exhausted”, confirming the number tracks whatever limit is live. The visitor just saw the critical error screen. To see the full message with file and line, turn on WordPress debug mode with logging and read wp-content/debug.log.
The file path at the end of the error matters less than you’d think. It shows where PHP happened to be when memory ran out, often wp-includes/plugin.php or the database class, which is rarely the code that used the memory.
When WP_MEMORY_LIMIT can’t help: code that runs before WordPress
Some code runs before wp-config.php is read, so your constant never applies to it. The common case is the Wordfence firewall in Extended Protection mode, which loads through PHP’s auto_prepend_file setting (often from a .user.ini file) ahead of WordPress. If your error points into wp-content/wflogs/ or a wordfence-waf.php file, the limit that matters is PHP’s own value. Raise it with Method 2, 3 or 5. A site can show a high WP_MEMORY_LIMIT in Site Health and still crash there at 128M.
When raising the memory limit is the wrong fix
More memory fixes a site that is a little short. It doesn’t fix code that keeps allocating until it hits any limit you give it. Signs you’re dealing with the second kind:
- You raised the limit from 256M to 512M and the error came back with the new, bigger number
- The error started right after a plugin or theme update
- It happens on one specific page, import, or admin action, not everywhere
- The “tried to allocate” value is huge (tens of megabytes in one go), which points at one oversized query or file
In those cases, find the code instead. Deactivate plugins one at a time on a staging copy (our plugin conflict guide walks through it), or install Query Monitor and watch the memory figure per page. Pages that load thousands of posts with 'posts_per_page' => -1, bloated autoloaded options, and runaway import scripts are the usual suspects.
Also keep the number sane. memory_limit is per PHP process, so ten PHP-FPM workers at 1G each can try to use 10 GB on a server that doesn’t have it. For most sites 256M is plenty, with 512M for WooCommerce stores or heavy page builders. Memory also has nothing to do with upload size: if a file is rejected as too big, see how to increase the WordPress max upload size instead.
Frequently asked questions
What is the default WordPress memory limit?
WP_MEMORY_LIMIT defaults to 40M on single sites and 64M on multisite, and WP_MAX_MEMORY_LIMIT defaults to 256M. WordPress never lowers PHP’s limit to match, so on most hosts the effective limit is whatever PHP is set to, commonly 128M or 256M.
How much memory does WordPress need?
A typical blog runs fine at 128M to 256M. WooCommerce stores, membership sites and heavy page builders are more comfortable at 256M to 512M. If a site needs more than 512M on normal page loads, a plugin is probably doing something wasteful.
Why didn’t WP_MEMORY_LIMIT change anything?
Either the line is below the wp-settings.php require (too late), PHP is already set higher than your value (WordPress only raises the limit), or your host locks memory_limit so ini_set() can’t change it. Check Tools > Site Health > Info > Server to see the real value.
What is the difference between WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT?
WP_MEMORY_LIMIT applies to every request, including the front end, REST API and admin-ajax.php. WP_MAX_MEMORY_LIMIT is used when WordPress raises memory for administrators on admin screens, during updates, for image processing and for WP-Cron.
Can I set the WordPress memory limit to -1?
PHP treats -1 as no limit, and WordPress accepts it. Don’t do it on a live site: one runaway request can then eat all the server’s RAM instead of failing with a clear error.
Does increasing the memory limit speed up WordPress?
No. The limit is a ceiling, not an allocation. Pages that already fit under it won’t get faster, and PHP only uses what a request actually needs.


