Site icon Connect Digital World

How to Fix ‘Allowed Memory Size of X Bytes Exhausted’ in WordPress

fix-cannot-connect-to-docker-daemon-unix-var-run-docker-sock

Quick fix: open wp-config.php and add this line just above the “That’s all, stop editing!” comment, then save:

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

Still stuck, or locked out of your dashboard? Keep reading. I will show you why this works, when you need one more line, and how to get back in.

Imagine you pack your school bag for a trip. You stuff in books, a lunchbox, a football, a jacket and a water bottle. Then you try to squeeze in one more thing, and the zip will not close. The bag is simply too small for everything you want to carry.

That is what happens to your WordPress website when you see “Fatal error: Allowed memory size of X bytes exhausted”. Your site tried to carry more than its “bag” can hold, so it stopped. Sometimes you see that message. Other times you only see a blank white page, which people call the White Screen of Death.

The good news is that this is one of the most fixable WordPress problems. In this guide, I will explain it step by step in simple words, so you can fix it yourself, even if you are locked out.

Quick Summary: The News in 30 Seconds

What the Error Looks Like

The full message usually looks like this:

Fatal error: Allowed memory size of 268435456 bytes exhausted
(tried to allocate 20480 bytes) in /home/yoursite/public_html/wp-content/plugins/some-plugin/file.php on line 123

Let us read it like a detective:

What does that big number mean?

Computers count memory in bytes. The numbers are huge, so people use “MB” (megabytes) instead. Here is a cheat sheet you can use to read your own error:

Number in the error Same as What it tells you
41943040 40 MB A small default limit. The one-line fix usually helps here.
67108864 64 MB Still small. Raising the limit should help.
134217728 128 MB Better, but heavy plugins can still run out.
268435456 256 MB Already high. If this shows in the dashboard, try the admin setting or look for a memory-hungry plugin.

You do not need to do the math yourself. Just match your number to the table. It tells you how big your “bag” is right now.

Fix 1: Add the Line to wp-config.php (Step by Step)

The wp-config.php file is the main settings file of your WordPress site. It lives in the root folder of your install, right next to the folders called wp-content, wp-admin and wp-includes. Here is how to edit it safely.

Step 1: Make a backup copy

Before you touch anything, copy the file and give the copy a new name, such as wp-config-backup.php. Or download a copy to your computer. This is like taking a photo of your room before you rearrange the furniture. If something goes wrong, you can put it back.

Step 2: Open the file

You have a few ways to open it:

Step 3: Add the line in the right place

Scroll down until you see a comment that says something like “That’s all, stop editing! Happy publishing.” Add your new line just above it:

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

/* That's all, stop editing! Happy publishing. */

Why above? Because WordPress finishes loading its settings at that point. A line placed after it is read too late, and nothing warns you that it was ignored. It is like handing in your homework after the teacher has already collected the books.

Step 4: Save and test

Save the file, then reload your site and the page that failed. If it works, you are done. If you still see the same error, read the next section. You may need the admin setting.

Fix 2: The Dashboard Needs Its Own Line

This is the part many guides skip, and it can save you an hour. WordPress uses two memory settings:

WordPress core code gives the admin limit a default of 256M, or the server’s PHP limit if that is higher. So if your error happens inside the dashboard and the number is already 268435456 (256 MB), setting WP_MEMORY_LIMIT to 256M changes nothing there. In that case, raise the admin limit too:

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

Put both lines above the “stop editing” comment. Do not add the same line twice, or PHP may warn you that the constant is already defined.

One more rule from WordPress developers: the front-end limit should not be bigger than the admin limit, and the admin limit should not be bigger than the server’s own PHP limit. Think of three boxes inside each other, from small to large.

Locked Out? How to Get Back In

Maybe you activated a new plugin or theme and now you only see a white page, or you cannot log in at all. Do not panic. Here are the safe steps, starting with the easiest.

Option 1: Use WordPress Recovery Mode

If a plugin or theme caused a fatal error, WordPress may catch it and send an email to the site admin address. That email has a special link that lets you log in to recovery mode and turn off the faulty plugin. Check your inbox (and spam folder) first.

Option 2: Turn off all plugins using the plugins folder

If you cannot reach the dashboard, connect with FTP or open your host’s File Manager. Then:

  1. Go to the wp-content folder.
  2. Rename the folder plugins to something like plugins_off.
  3. Try to open your site or the login page again.

WordPress looks for a folder called “plugins” to load every plugin. When it cannot find it, all plugins are switched off at once. If your site comes back, you know a plugin was the problem.

Now rename the folder back to plugins. Log in, and turn plugins on one at a time until the white screen returns. The last one you turned on is your culprit. You can also rename plugin folders one by one inside the plugins folder to find it faster.

Option 3: Switch the theme the same way

If the plugins are not the problem, go to wp-content/themes and rename the folder of your active theme. WordPress will then fall back to a default theme, if one is installed.

Option 4: Ask WordPress to tell you the real reason

Not sure what is going on? You can turn on the debug log. Add these lines to wp-config.php, above the “stop editing” comment:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

WordPress will now write problems into a file at wp-content/debug.log. Open it, and look for the words “Allowed memory size”. The line usually names the plugin or theme file. When you finish, turn debugging off again, because you do not want a growing log file on a live site.

Why Are There Two Memory Settings? A Simple Table

Setting Where it works School analogy Default (per WordPress code)
WP_MEMORY_LIMIT Front end (visitors) The daily school bag About 40 MB on a single site
WP_MAX_MEMORY_LIMIT Admin area (dashboard) The big suitcase for sports day 256 MB, or the server limit if higher
PHP memory_limit (server) The whole server for your account The size of your classroom locker Set by your host

Notice the last row. Even a huge suitcase cannot fit in a tiny locker. That brings us to the next problem.

What If the wp-config.php Fix Does Not Work?

Both WordPress settings are requests, not promises. Your web host can set a PHP memory limit on the server, and WordPress cannot go above it. If you asked for 512M but the host allows only 128M, you will still hit the wall. Here is what to try next.

1. Check what your site really has

In your dashboard, you can open Tools, then Site Health, then the Info tab, then the Server section. You can usually see the PHP memory limit there. If the number does not match what you wrote in wp-config.php, the server is overruling you.

2. Use your host’s PHP settings

Many hosts give you a control-panel page for PHP settings (in cPanel, this is often called a MultiPHP INI editor or a similar name). Look for a setting named memory_limit and raise it there. Some hosts let you use a php.ini file instead:

memory_limit = 256M

Every host works a little differently, so check your host’s help pages.

3. Try the .htaccess file (careful)

On some Apache servers, you can add a line to the .htaccess file in your site’s root folder:

php_value memory_limit 256M

Be careful. On servers that do not allow this, the line can cause a “500 Internal Server Error”. Make a backup of .htaccess first, and remove the line right away if your site breaks.

4. Ask your host

If nothing works, send a short message to your hosting support: “Please raise the PHP memory_limit for my account to 256M.” It is a very common request. Some cheap plans cap memory, and then the real answer may be a better plan.

Find the Real Culprit (Do Not Just Throw Memory at It)

Raising the limit is like buying a bigger bag. It helps, but if someone keeps putting rocks in your bag, it will fill up again. Here are common memory-hungry things:

What to do:

  1. Update your plugins, theme and WordPress itself.
  2. Remove plugins you do not use.
  3. Use the debug log to find the exact plugin named in the error.
  4. Check if the plugin has a newer version, or ask its support team.
  5. If a plugin keeps failing, look for a lighter alternative.

Also be careful with giant numbers. Setting something huge like 1024M “just in case” is not a good idea. A hosting guide warns that very high values without a reason can hurt your hosting account’s performance.

How Much Memory Should You Choose?

There is no magic number. Community guides usually suggest values from 128M up to 512M or more, depending on how big and busy your site is. Here is a friendly starting guide. These are common suggestions, not official rules:

Type of site A sensible starting point
Small blog with a few plugins 128M to 256M
Business site with a page builder 256M
Online shop or membership site 256M to 512M (check with your host)
Heavy jobs like big imports A higher admin limit, only while needed

Start small. Raise the number only if the error comes back. Then look for the plugin causing it.

Common Mistakes to Avoid

How to Stop This Error from Coming Back

A Simple Routine to Remember

  1. Read the number. Is it 40 MB, 128 MB or 256 MB?
  2. Add the line. Put WP_MEMORY_LIMIT in wp-config.php, above the “stop editing” comment.
  3. Dashboard still failing? Add WP_MAX_MEMORY_LIMIT too.
  4. Still no change? Ask your host about the server limit.
  5. Locked out? Rename the plugins folder, then find the culprit.

Five small steps, and most memory errors will be gone in a few minutes.

Reminder: Check the Official Pages

WordPress, PHP and hosting dashboards change over time. Default values, menu names and recommended settings can shift after an update. Before you edit an important site, look at the official WordPress documentation for wp-config.php and your host’s help pages for the latest steps.

Simple Word List (Glossary)

Frequently Asked Questions (FAQ)

1. What does “Allowed memory size of X bytes exhausted” mean?

It means a script on your site tried to use more PHP memory than it is allowed. The site stops, and you see the error or a white screen.

2. What is the quickest way to fix it?

Add define(‘WP_MEMORY_LIMIT’, ‘256M’); to wp-config.php, above the “stop editing” comment, and save the file.

3. Why did the fix not work in my dashboard?

The admin area uses its own setting, WP_MAX_MEMORY_LIMIT, which already defaults to 256M. Raise that one too, or look for a memory-hungry plugin.

4. Can I fix this if I cannot log in?

Yes. Edit wp-config.php with FTP or your host’s File Manager. You can also rename the plugins folder to switch every plugin off, then find the faulty one.

5. Where exactly should I put the line in wp-config.php?

Put it above the comment that says “That’s all, stop editing!”. Lines placed after it can be ignored.

6. Why does my memory limit not change after I edit the file?

Your host may cap PHP memory at the server level. WordPress can only ask for more. Check Site Health, your host’s PHP settings, or contact support.

7. Is 256M enough?

For many sites, yes. Busy shops or sites with heavy page builders may need more. Raise it only when needed, and look for the plugin causing the problem.

8. Is it safe to set a very high limit like 1024M?

It is not recommended without a reason. Very high values can hurt your hosting account’s performance and may be capped anyway.

9. Can a plugin or theme cause this error?

Yes, that is the most common cause. A heavy or badly written plugin or theme can use up all the memory, especially right after you activate it.

10. Should I edit .htaccess or php.ini instead?

Try wp-config.php first. Use php.ini or your host’s PHP settings if you need to raise the server limit. Use .htaccess carefully, since a wrong line can break your site.

Final Thoughts

The “Allowed memory size exhausted” error sounds scary, but it only means your site’s bag is too small for what it is carrying. Add the line to wp-config.php, raise the admin limit if you need to, check with your host, and find any plugin that keeps stuffing the bag too full.

Did this guide get your site working again? Tell me in the comments which step fixed it for you. If you are still stuck, share the number from your error message and what you did just before it appeared, so other readers can help.

At Connect Digital World, we explain tech problems in simple words. Come back soon for more easy guides on WordPress and everyday tech.

Sources and further reading: WordPress core source, default-constants.php (github.com/WordPress/WordPress/blob/master/wp-includes/default-constants.php); WordPress Core Trac tickets 32075 and 56390 (core.trac.wordpress.org/ticket/32075 and core.trac.wordpress.org/ticket/56390); WordPress Support, “Common WordPress Errors” (wordpress.org/support/article/common-wordpress-errors/); WordPress Developer Resources, “Editing wp-config.php” (developer.wordpress.org/advanced-administration/wordpress/wp-config/); WPBeginner, “How to Fix the WordPress White Screen of Death” (wpbeginner.com/wp-tutorials/how-to-fix-the-wordpress-white-screen-of-death); Elementor, “How to Increase the WordPress Memory Limit” (elementor.com/blog/how-to-increase-wordpress-memory-limit/); ITMonks, “How to Increase the WordPress Memory Limit in wp-config” (itmonks.com/blog/wp-development/wp-config-memory-limit/); Webzi Help, “How to fix WordPress memory limit errors” (help.webzi.mx/portal/en/kb/articles/how-to-fix-wordpress-memory-limit-errors); Ahosting, “Understanding wp-config.php Settings” (ahosting.net/faq/wordpress-hosting/understanding-wp-config-php-settings.html).

Exit mobile version