Increase WordPress Memory Limit. How to Fix “Allowed Memory Size Exhausted” Error

Did you encounter the error message “Allowed memory size of 268435456 bytes exhausted.” or “Allowed memory size of 536870912 bytes exhausted“?

“This error can be frustrating, as it can prevent you from accessing your website and completing essential tasks. This article will explain how to Increase WordPress Memory Limit and fix the memory exhaust error.

If you get a high memory consumption and memory exhaust error while created a backup with WP STAGING, please read this article.

What Causes the “Allowed Memory Size of X Bytes Exhausted” Error?

The “Allowed memory size of 268435456 bytes exhausted” error occurs when your WordPress site consumes too much memory. PHP, the programming language that powers WordPress, has limited memory for each process. When your site exceeds this limit, PHP throws an error and stops the process, which results in an error message.

Several factors can contribute to high memory consumption on your WordPress site. These include:

  1. Large image files: Large images can take up significant memory, especially if not optimized for the web.
  2. Plugin or theme conflicts: Some plugins and themes may conflict with each other or with WordPress, causing memory leaks and high memory usage.
  3. Caching issues: Improperly configured caching plugins can cause memory usage to spike.
  4. Traffic spikes: If your site experiences a sudden surge in traffic, it can cause high memory usage.

How to Fix the “Allowed Memory Size of X Bytes Exhausted” Error

Here are some steps you can take to fix the “Allowed memory size of X bytes exhausted” error:

Increase PHP Memory Limit

The easiest way to fix this error is to increase the PHP memory limit. You can do this by adding the following code to your wp-config.php file:

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

This code sets the memory limit to 256 megabytes. You can adjust and increase this number based on your site’s needs. Increase the value until you get no more memory-exhausted errors.

Make sure you add the WP_MEMORY_LIMIT constant before this block of code:

/* That's all, stop editing! Happy blogging. */
 /** Absolute path to the WordPress directory. */
 if ( !defined('ABSPATH') )
 define('ABSPATH', dirname(__FILE__) . '/');
 /** Sets up WordPress vars and included files. */
 require_once(ABSPATH . 'wp-settings.php');
Attention: If you add the WP_MEMORY_LIMIT value at the end of the wp-config.php and not before this block, the modification will not have any effect!

Optimize Images

To reduce memory usage, you should optimize your images for the web. You can use image optimization plugins like Smush or EWWW Image Optimizer to compress your images without losing quality.

Deactivate Plugins and Themes

If you suspect a plugin or theme is causing high memory usage, you can deactivate them individually to identify the culprit.

Check Your Caching Settings

Ensure your caching plugin is properly configured to avoid memory leaks.

Upgrade Your Hosting Plan

If your site experiences frequent traffic spikes, you may need to upgrade your hosting plan to handle the increased traffic.

If this does not resolve your WordPress / PHP memory issues, follow the advice below:

How to fix the “Memory Exhausted” Error

First, check out how much memory PHP assigns and look at the system info log.
Go to WP Staging > Tools > System Info to do so:

This should be at least 128M or, even better, 256M or more.

A more precise alternative is to create an empty file and add the code below to it:

<?php echo phpinfo();
  • Save the file as info.php and upload it to your website’s root via FTP or a file manager plugin.
  • Now open and find the line memory_limit

This line tells you the exact amount of memory in megabytes your site uses.

For medium WordPress sites, this memory limit should be at least 128M or better than 256M.

If the memory limit is lower, you need to raise it. You can increase the PHP memory limit by editing the PHP.ini. Open the PHP.ini and find the line memory_limit and change the value to:

memory_limit = 256M
  • Ask your hosting provider where you can find the PHP.ini.

If you have no access to that file, you can try to edit your .htaccess file and add the code below to it:

php_value memory_limit 256M

Now, reopen the file info.php or the system info log and check if the memory limit increases.

If you were successful and phpinfo() shows the correct memory limit, reload your website, and the error “Allowed memory size exhausted” should be gone.

If you cannot increase the memory limit alone, please ask your hosting provider if they can do it.


The “Allowed memory size of X bytes exhausted” error can be frustrating, but it’s a common issue that can be fixed with the steps outlined in this article. By increasing your PHP memory limit, optimizing your images, deactivating conflicting plugins and themes, checking your caching settings, and upgrading your hosting plan if necessary, you can reduce memory usage and prevent this error from occurring.

Updated on September 26, 2023