How to fix "Allowed memory size exhausted" in WordPress
A page needed more memory than PHP is allowed to use, so PHP stopped it. Raising WordPress's memory limit in wp-config.php clears it on most hosts. The error message itself names the file that asked for too much, which tells you what to look at if it comes back.
- By
- WP Ministry
- Published
- Tested on
- WordPress 7.1.3, PHP 8.3.35
In short
- The limit is a safety setting, not a fault in your site. One page asked for more than it allows.
- Adding one line to wp-config.php raises the limit on most hosts.
- If the line changes nothing, your host sets a ceiling that only they can lift.
- The message names a file. If it is inside a plugin's folder, that plugin is what is using the memory.
PHP, the language WordPress is written in, gives each page a fixed amount of memory to work with. When a page asks for more, PHP stops it and reports "Allowed memory size of … bytes exhausted". WordPress then shows visitors "There has been a critical error on this website" in its place.
The number in the message is the limit in bytes: 134217728 is 128 MB, and 268435456 is 256 MB.
Where it goes wrong
A page request passes through each of these in turn. This one comes from PHP, the language WordPress runs on.
- Browser
- DNS
- HTTPS
- CDN or firewall
- Web server
- PHP (this error comes from here)
- WordPress
- Database and files
What causes it
The memory limit is lower than the site now needs
CommonSites grow. A limit that suited a new site can be too small once it has a page builder, a shop and a dozen plugins.
One plugin or theme is using far more than the rest
CommonA plugin that loads a whole file into memory, or that has a fault, can use up any limit however high it is set.
The host caps memory below what you set
SometimesOn some hosting plans the limit in the server's own settings cannot be raised from inside WordPress.
How to fix it
Raise WordPress's memory limit
- Easy
- Back up first
- About 5 minutes
- Steps tested on WordPress 7.1.3
Step 1: Open wp-config.php
It is in the folder WordPress is installed in, beside the
wp-contentfolder.Step 2: Add the line above "That's all, stop editing"
Anything added below that line is read too late to count.
wp-config.phpdefine( 'WP_MEMORY_LIMIT', '256M' );Step 3: Save the file and reload the page that failed
If it loads, the limit was the cause. If nothing changes straight away, wait a few seconds and reload: PHP can go on using its stored copy of the file for a moment after you save.
WordPress can only raise the limit, never lower it, and only as far as your host allows. If the page still fails with the same number in the message, the host's ceiling is in the way.
To undo it: Remove the line from wp-config.php.
Find what is using the memory
- Takes care
- Low risk
- About 15 minutes
- Steps tested on WordPress 7.1.3
The error message ends with the path of the file that asked for the memory. WordPress hides that from visitors, but will write it to a log if you ask.
Step 1: Turn the debug log on
In
wp-config.php, find the linedefine( 'WP_DEBUG', false );and replace it with these three. If you have WP-CLI, the commands below do the same.wp-config.phpdefine( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );Step 2: Load the page that fails
Once is enough.
Step 3: Read the log
Open
wp-content/debug.logand find the line with "Allowed memory size". The path at the end of it shows where the memory ran out. A path throughwp-content/plugins/followed by a plugin's folder name points at that plugin.Step 4: Turn the debug log off again
Put the line back to
define( 'WP_DEBUG', false );. The log can hold details you do not want left on a public server, so deletedebug.logwhen you have read it.
wp config set WP_DEBUG true --raw
wp config set WP_DEBUG_LOG true --raw
wp config set WP_DEBUG_DISPLAY false --rawWhen you have what you need:
wp config set WP_DEBUG false --raw
wp config set WP_DEBUG_LOG false --rawSwitch that plugin off and load the page again. If it loads, you have found the cause: update the plugin, replace it, or tell its author.
Ask the host to raise PHP's own limit
- Easy
- No risk
- About 15 minutes
If the line in wp-config.php makes no difference, the limit is set in the server's PHP settings, above WordPress.
Step 1: Look for a PHP settings page in your hosting panel
Many hosts let you change
memory_limityourself, under a name such as "PHP settings" or "PHP options".Step 2: If there is none, ask support
Ask them to set PHP's
memory_limitto 256M for your site, and whether your plan allows it.
When to get help
If the limit is at 256M and the error is still there, raising it further hides the problem instead of solving it. Something is using memory it should not, and finding it means reading the log and testing with plugins switched off.
Common questions
How much memory does WordPress need?
WordPress asks for 40 MB by default and allows itself up to 256 MB in the dashboard. A site with a page builder or a shop commonly needs 256 MB for visitors as well.
Is a higher limit always better?
No. The limit is there so that one runaway page cannot take the whole server's memory. Set it to what the site needs and find out why if it needs more.
Why does it only happen sometimes?
Different pages do different work. Uploading a large image, running a backup or importing products needs far more memory than showing a post.
- GuideLocked out of WordPress admin: find which lockout you have and get back in
- GuideSlow WordPress admin: how to find the cause and fix it
- ResourceWooCommerce checkout is down: a runbook
- GuideWordPress site not showing up on Google: what to check, in order
- Guideadmin-ajax.php high CPU usage in WordPress: how to find what is calling it
- GuideHow to change WordPress permalinks without breaking your old links

