in

How to Fix Memory Limit Error and Keep WordPress Site Going

Dear reader,

If you‘ve been running a WordPress site, you‘ve likely encountered that dreaded "fatal error: allowed memory size exhausted" message. As an experienced WordPress user myself, I totally understand how frustrating these memory limit errors can be. But don‘t worry – with the right approach, you can overcome this issue and continue leveraging the power of WordPress.

In this comprehensive guide, I‘ll walk you through the ins and outs of WordPress memory limits – from causes to solutions. I‘ve also included interesting stats, expert tips, and best practices to help you optimize your site and prevent future errors. So let‘s get started!

Why Memory Limit Errors Occur in WordPress

Before diving into solutions, it‘s important to understand what causes these pesky memory limit errors.

wordpress-error

As a quick refresher, WordPress is an open-source content management system (CMS) built on PHP and MySQL. It allows you to easily build and manage a website or blog.

Now here‘s the catch – WordPress doesn‘t have a built-in memory limit. The memory limit is actually set by PHP on your web server. By default, PHP limits vary between 128MB on budget hosts and 256MB on managed WordPress hosts.

When your WordPress site tries to use more memory than this limit, you‘ll get the "fatal error" message.

According to HostingFacts, the most common triggers are:

  • Incompatible plugins or themes: Poorly coded plugins can take up excessive memory, especially if they‘re not compatible with your WordPress version. Switching to lightweight alternatives usually helps.

  • Large databases: As your database grows with more posts/comments/media, the memory required for queries also increases.

  • High-traffic spikes: More visitors means more concurrent requests and memory usage.

  • Low server resources: Outdated or overloaded servers struggle with memory demands.

Now let‘s explore these causes and solutions in more detail.

Pinpointing the Exact Cause

Instead of blindly trying different fixes, I recommend first pinpointing the root of your WordPress memory issues.

Here are some easy ways to diagnose the problem:

Check WordPress Site Health

The built-in Site Health tool offers an overview of your WordPress installation, including the memory limit.

To find it, go to Tools → Site Health in your WP dashboard. Click on the Info tab, then scroll down and expand WordPress Constants.

Site Health Info WordPress Memory Limit

Look for the WP_MEMORY_LIMIT value. The default is 40MB, which is low for most websites. If your limit is under 64MB, an increase could help.

Look in wp-config.php

The wp-config.php file contains key WordPress configuration settings, including the memory limit.

To view it, install a file editor like WP File Manager and navigate to wp-config.php.

Search for this line:

define(‘WP_MEMORY_LIMIT‘, ‘64M‘); 

As you can see, the memory limit is set to 64MB here. Modify as needed.

Check Server php.ini Settings

The PHP memory limit is actually defined in php.ini – so that‘s the source of truth.

Your hosting control panel allows you to view and edit php.ini. Under public_html, look for the memory_limit line:

memory_limit = 128M

If it‘s too low, increase to at least 64MB.

Monitor Memory Usage

To confirm memory issues, monitor your site‘s live memory usage with a plugin like P3 Profiler.

This helps visualize spikes from themes, plugins, hooks, etc. so you can pinpoint heavy resources.

P3 Profiler WordPress memory usage

So in summary, take some time to diagnose before applying fixes. Understanding the root cause will save you time and effort.

5 Effective Ways to Increase the WordPress Memory Limit

Once you‘ve identified the source of excessive memory usage, you can start troubleshooting. Here are 5 effective methods to raise the memory limit and stop fatal error messages:

1. Modify wp-config.php

As mentioned earlier, wp-config.php controls the WP_MEMORY_LIMIT constant in WordPress. This is the recommended way to raise the memory limit.

To change it, open wp-config.php and add this line before the final comments:

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

The example sets the limit to 256MB, but you can enter any value based on your needs. Save changes and test your site.

Tip: Many hosts set 128M or 256M as a "hard cap" in php.ini. So increasing wp-config.php beyond that may not work. Try the next method if you hit another error.

2. Edit php.ini Settings

For full control, edit the memory_limit value in the php.ini file itself:

memory_limit = 256M

This globally overrides the WordPress constant.

Restart your web server to apply changes. Now your PHP scripts can utilize up to 256MB without errors.

Warning: Some hosts disable php.ini edits to ensure stability. Check with your provider before making changes.

3. Use a .htaccess File

If you can‘t access php.ini, try creating an .htaccess file in your WordPress root folder with:

php_value memory_limit 256M

This sets the memory limit for PHP pages only. Clear your cache after adding the code.

However, .htaccess tweaks can break certain servers. So test carefully first.

4. Install a Memory Limit Plugin

For an instant boost, install a dedicated plugin like WP Memory Limit to override the setting:

WP Memory Limit plugin

After activating, head to Settings → Memory Limit to enter your new value.

This method works great for quick fixes. But plugins can impact performance.

5. Upgrade Web Hosting Plan

If your WordPress memory errors persist despite above fixes, the underlying problem could be your web hosting server itself.

Upgrading to a managed WordPress host like WP Engine usually solves these issues. Their optimized servers come with higher resources and regular updates.

For instance, WP Engine‘s Startup plan provides:

  • 40x more memory – 1GB limit
  • 4x more storage – 10GB SSD
  • 4x more computing power
  • 20x faster I/O speed

Migrating to a specialized WordPress host is the best long-term solution if your existing server is outdated or overloaded. Their infrastructure and expertise helps avoid resource limitations.

So in summary:

  • Modify wp-config.php if you have some hosting access
  • Edit php.ini memory values for a server-wide change
  • Use .htaccess for a quick fix, if allowed
  • Install a memory limit plugin like WP Memory Limit
  • Switch to a managed WordPress host for maximum resources

Now let‘s move on to some best practices to avoid these pesky errors altogether.

Expert Tips to Prevent WordPress Memory Limit Errors

In addition to reactive troubleshooting, there are some proactive steps you can take to avoid memory headaches:

1. Select Lightweight Themes and Plugins

Carefully assess the resource impact of any themes and plugins you install. Premium plugins from top developers like WPMU DEV are optimized for performance.

Avoid free plugins with lots of unnecessary bloat just for the sake of more features.

Tools like Query Monitor also help identify heavy plugins:

Query Monitor WordPress

2. Enable Caching and CDNs

Caching stores preprocessed data to serve repeated requests faster. This reduces database queries and memory needs.

Must-have caching plugins include WP Rocket and WP Fastest Cache.

Using a content delivery network (CDN) like Cloudflare also offloads assets from your main server.

3. Delete Unnecessary Data

Delete old post revisions, comments, orphaned media, and spam regularly.

Reducing the size of wp_posts and wp_comments tables lowers the memory required for queries.

Plugin helpers like WP-Optimize make the cleanup process easy.

4. Optimize Images

MEDIA BASED IOS Sofeware LTD revealed that unoptimized images account for over 65% of average website size.

High-resolution photos may look nice but quickly eat up storage space and memory.

Use EWWW Image Optimizer or ShortPixel to compress images without quality loss. Downsize large images to thumbnails. Strip EXIF data from JPEGs.

5. Split Infrequent Traffic Spikes

If an upcoming promotion will direct a flood of traffic to your site, leverage cloud flare protection and a CDN to cache static assets.

Consider temporarily disabling non-critical plugins to lower memory utilization during traffic spikes.

6. Upgrade Your Web Hosting

No amount of optimization can overcome the limits of an outdated shared server with inadequate resources.

Upgrading to a modern WordPress-optimized host like Kinsta or Pagely can eliminate memory errors and speed up your site.

Their enterprise-grade infrastructure can smoothly handle traffic surges withoutbottlenecks. For instance, Kinsta‘s premium plans include:

  • 15x more memory – up to 768MB limit
  • 20x faster CPUs and SSD storage
  • Built-in CDN, caching, security, and auto-scaling

The premium may be worthwhile if memory issues constantly plague your site.

Finding the Ideal Memory Limit for Your WordPress Site

Instead of arbitrarily setting a high memory limit, aim for the optimal value your particular site needs.

Here are a few rules of thumb when deciding on a new memory limit:

  • 512MB – Advanced sites with heavy plugins
  • 256MB – Typical pub/sub sites with some plugins
  • 128MB – Basic sites with little functionality
  • 64-96MB – Very simple sites

Of course, these are just general starting points – monitor your live usage to fine-tune.

Striking the right balance avoids both memory exhaustion errors and over-provisioning.

Conclusion

I hope this guide gave you a comprehensive overview of how to resolve WordPress memory limit errors for good.

The key takeaways are:

  • Pinpoint the cause before blindly applying fixes
  • Adjust wp-config.php for a quick increase
  • Tweak PHP and server settings for more control
  • Enable caching, CDNs, and image optimization
  • Switch to a managed WP host for more resources
  • Find the optimal memory limit specific to your site

Please let me know in the comments if you have any other tips for dealing with WordPress memory issues! I‘m always looking to improve my own understanding as well.

AlexisKestler

Written by Alexis Kestler

A female web designer and programmer - Now is a 36-year IT professional with over 15 years of experience living in NorCal. I enjoy keeping my feet wet in the world of technology through reading, working, and researching topics that pique my interest.