How to Fix WordPress Memory Exhausted Error

What Is the WordPress Memory Exhausted Error?

The WordPress memory exhausted error happens when your site runs out of allocated PHP memory. You’ll see error messages like:

  • “Fatal error: Allowed memory size of X bytes exhausted”
  • “Out of memory (allocated X) (tried to allocate Y bytes)”
  • “WordPress memory limit exceeded”

This error appears when WordPress tries to execute a task that requires more RAM than your server allows. It commonly occurs during plugin installations, theme updates, image uploads, or when running resource-intensive operations like importing content or generating reports.

Unlike other errors, this one explicitly tells you the problem: WordPress needs more memory than it currently has access to. The good news is that increasing memory limits is straightforward and usually takes less than 5 minutes.


Common Causes of Memory Exhausted Errors

  • Default memory limit too low — PHP default is often 32MB or 64MB, insufficient for modern WordPress
  • Too many plugins active — Each plugin consumes memory; 30+ plugins can exhaust resources
  • Large media files — Uploading or processing high-resolution images
  • Poorly coded plugins — Inefficient code with memory leaks
  • Complex themes — Page builders and multipurpose themes using excessive resources
  • WooCommerce or membership sites — E-commerce operations require more memory
  • Import/export operations — Migrating large databases or content
  • Backup plugins running — Creating backups of large sites

Solution 1: Increase Memory Limit in wp-config.php

This is the most common and effective fix.

  1. Via FTP or File Manager, open wp-config.php in your WordPress root directory
  2. Find this line:
    /* That's all, stop editing! Happy publishing. */
    
  3. Add this code before that line:
    define('WP_MEMORY_LIMIT', '256M');
    define('WP_MAX_MEMORY_LIMIT', '512M');
    
  4. Save the file
  5. Refresh your website and test

What these values mean:

  • WP_MEMORY_LIMIT — Memory available for normal WordPress operations
  • WP_MAX_MEMORY_LIMIT — Memory available for admin area operations (higher because admin tasks are more intensive)

Common memory limit recommendations:

  • Small blog: 128M
  • Standard site: 256M
  • WooCommerce store: 512M
  • Large membership site: 1024M (1GB)

If 256M doesn’t work, try 512M. Most shared hosting allows up to 512M.


Solution 2: Increase Memory Limit via php.ini

If wp-config.php changes don’t work, your hosting might enforce limits at the PHP level.

Create or edit php.ini:

  1. Via FTP, check if php.ini exists in your WordPress root directory
  2. If not, create a new file named php.ini
  3. Add these lines:
memory_limit = 256M
upload_max_filesize = 128M
post_max_size = 128M
max_execution_time = 300
max_input_time = 300
max_input_vars = 3000
  1. Save and upload to your root directory
  2. Test your site

Note: Some hosts require php.ini in specific folders. Common locations:

  • Root directory: /public_html/php.ini
  • Public HTML: /public_html/
  • wp-admin: /wp-admin/php.ini

If unsure, contact your hosting provider for the correct location.


Solution 3: Increase Memory Limit via .htaccess

If you have Apache server, you can set PHP values in .htaccess.

  1. Via FTP, open .htaccess in your WordPress root
  2. Add these lines at the top (before the WordPress rules):
php_value memory_limit 256M
php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value max_execution_time 300
php_value max_input_time 300
  1. Save the file
  2. Test your site

If this causes a 500 error, your server doesn’t allow PHP values in .htaccess. Remove those lines and use another method.


Solution 4: Contact Your Hosting Provider

If none of the above work, your hosting provider enforces hard limits at the server level.

What to ask your host:

  1. “What is the maximum PHP memory limit allowed on my plan?”
  2. “Can you increase my PHP memory limit to 512M?”
  3. “Do I need to upgrade to a higher hosting plan for more memory?”

Most quality hosts can adjust this within minutes via their control panel. Some budget hosts require plan upgrades.

Check your hosting control panel:

Many hosts (cPanel, Plesk, custom panels) have PHP settings managers:

  1. Log in to your hosting control panel
  2. Look for “PHP Settings,” “PHP Configuration,” or “MultiPHP INI Editor”
  3. Find memory_limit setting
  4. Change to 256M or 512M
  5. Save changes

Solution 5: Disable and Debug Plugins

If you can’t increase memory or keep hitting limits, reduce memory consumption.

Identify memory-heavy plugins:

  1. Deactivate all plugins (via Plugins → Installed Plugins or rename the plugins folder via FTP)
  2. Reactivate plugins one by one
  3. After each activation, perform the action that caused the error
  4. When the error returns, you’ve found the problematic plugin

Common memory-intensive plugins:

  • Page builders (Elementor, Divi, WPBakery)
  • Backup plugins (UpdraftPlus, BackupBuddy)
  • Analytics plugins
  • Social media auto-posters
  • SEO plugins with link monitoring

Consider alternatives or remove unnecessary plugins entirely.


Solution 6: Optimize Theme Performance

Themes with excessive features consume significant memory.

Check if your theme is the issue:

  1. Go to Appearance → Themes
  2. Activate a default WordPress theme (Twenty Twenty-Three)
  3. Test if the memory error disappears

If the error is gone, your theme is the culprit. Options:

  • Contact theme developer for optimization help
  • Disable unused theme features in theme settings
  • Switch to a lighter theme (GeneratePress, Astra, Kadence)
  • Use a child theme with only essential features enabled

Multipurpose themes with built-in page builders are notorious for memory issues.


Solution 7: Check Current Memory Limit

Before making changes, verify your current limit.

Method 1: Create phpinfo.php file

  1. Via FTP, create a file named phpinfo.php in your root directory
  2. Add this code:
    <?php phpinfo(); ?>
    
  3. Visit yoursite.com/phpinfo.php
  4. Search for “memory_limit” (Ctrl+F)
  5. Note the current value
  6. Delete phpinfo.php after checking

Method 2: Check via WordPress

Install the “Health Check & Troubleshooting” plugin:

  1. Go to Tools → Site Health → Info → Server
  2. Look for “PHP memory limit”

This shows what WordPress can actually access, not just what you configured.


Solution 8: Optimize Database and Clear Caches

A bloated database forces WordPress to load more data into memory.

Clean up database:

  1. Install “WP-Optimize” or “Advanced Database Cleaner” plugin
  2. Remove post revisions, spam comments, and transients
  3. Optimize database tables

Clear all caches:

  1. If using a caching plugin (WP Super Cache, W3 Total Cache), empty all caches
  2. Clear browser cache
  3. Clear server-side cache (contact host if needed)

Via wp-cli (if available):

wp cache flush
wp transient delete --all
wp db optimize

Solution 9: Optimize Image Processing

Large image uploads consume massive amounts of memory.

Reduce image sizes before uploading:

  • Resize images to web-appropriate dimensions (1920px max width for hero images)
  • Use tools like TinyPNG or ImageOptim before uploading
  • Install “Smush” or “ShortPixel” plugins for automatic optimization

Disable WordPress image processing temporarily:

Add to wp-config.php:

define('WP_MAX_IMAGE_SIZE', 1920);
add_filter('big_image_size_threshold', '__return_false');

This prevents WordPress from creating multiple image sizes, reducing memory usage.


Solution 10: Upgrade Your Hosting Plan

If you’ve tried everything and still hit memory limits, your hosting plan might be inadequate.

Signs you need better hosting:

  • Memory exhausted errors persist even at 256M
  • Slow site performance even with optimization
  • Hosting provider won’t increase limits
  • Shared hosting with severe resource restrictions

Upgrade options:

  • Better shared hosting — Hosts like SiteGround, Kinsta, or WP Engine offer higher limits
  • VPS hosting — Dedicated resources, full control over PHP limits
  • Managed WordPress hosting — Optimized for WordPress, higher default limits
  • Cloud hosting — Scalable resources based on traffic

Prevention Tips

  • Start with adequate memory limits from day one (256M minimum)
  • Monitor plugin memory usage with plugins like “Query Monitor”
  • Regularly audit and remove unused plugins
  • Optimize images before uploading
  • Use lightweight themes when possible
  • Keep WordPress and plugins updated (newer versions often use less memory)
  • Schedule resource-intensive tasks (backups, imports) during low-traffic periods
  • Use external services for heavy tasks (offload backups to cloud services)

From my experience: I once spent 3 hours troubleshooting memory errors on a client’s WooCommerce site, trying every optimization trick I knew. The issue? They had 47 plugins installed, including 3 different SEO plugins doing the same job. After cleaning up to 18 essential plugins, memory usage dropped by 60% and the errors disappeared completely.

Related: If increasing memory doesn’t solve your problems, you might be dealing with other issues. Check How to Fix WordPress 500 Internal Server Error or How to Fix WordPress Server Error After Update for additional troubleshooting steps.


Conclusion

WordPress memory exhausted errors are usually simple to fix: increase the memory limit in wp-config.php to 256M or 512M. If that doesn’t work, the problem is either server-level restrictions (contact your host) or excessive memory consumption from too many plugins or poorly optimized themes. The key is understanding that WordPress’s default memory allocation is often too conservative for modern sites with multiple plugins and complex themes. Setting adequate memory limits from the start prevents these errors entirely.

Leave a Comment