Your WordPress site just displayed a white screen with a cryptic error message like:

Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 2048 bytes) in /home/username/public_html/wp-includes/plugin.php on line 432

This is one of the most common WordPress errors we see at Canadian Web Hosting—and the good news is it is almost always fixable without restoring from backup. This guide walks you through the systematic diagnosis and permanent fix.

The Quick Fix

If you just need your site back online fast, here is the most common solution:

Increase the PHP Memory Limit

Add this line to your wp-config.php file, just before the “stop editing” comment:

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

Upload the file via FTP or cPanel File Manager, then refresh your site. If the error disappears, you have solved the immediate problem.

But wait—increasing memory is often just treating the symptom. If your site was working fine and suddenly hit this limit, something changed. A plugin update, a new theme, a traffic spike, or a poorly coded function could be the real culprit. The rest of this guide helps you find and fix the underlying cause.

Root Causes and How to Diagnose Each

The memory exhausted error means WordPress tried to use more RAM than PHP allows. The question is why. Here are the five most common causes, in order of likelihood.

1. A Memory-Hungry Plugin

How to confirm: If the error appeared after a plugin update or installation, that plugin is the prime suspect. Some plugins—especially page builders, SEO tools, and backup utilities—have memory leaks or inefficient database queries.

Diagnosis steps:

  • Enable WP_DEBUG in wp-config.php: define( 'WP_DEBUG', true );
  • Add define( 'WP_DEBUG_LOG', true ); to write errors to /wp-content/debug.log
  • Reproduce the error and check debug.log—the file path will often point to the responsible plugin
  • Alternatively, disable plugins one by one via FTP (rename /wp-content/plugins/plugin-name to plugin-name.disabled) until the error stops

The fix: Replace the problematic plugin with a lighter alternative, contact the developer, or keep it disabled if non-essential.

2. An Inefficient Theme or Child Theme

How to confirm: If the error occurs on specific pages (like the homepage or archive pages) but not others, your theme may be running heavy queries or loading excessive assets.

Diagnosis steps:

  • Temporarily switch to a default theme (Twenty Twenty-Five) via FTP: rename your current theme folder in /wp-content/themes/
  • WordPress will fall back to a default theme
  • If the error disappears, your theme is the culprit

The fix: Contact your theme developer, switch to a lighter theme, or optimise the theme code. Query Monitor plugin can identify which theme functions are consuming memory.

3. Large Media Library or Unoptimised Images

How to confirm: If the error occurs when uploading images or when Image Regenerate plugins run, your media library may be overwhelming PHP memory during processing.

Diagnosis steps:

  • Check if the error occurs only during image operations
  • Install Query Monitor and look for memory spikes during media uploads

The fix:

  • Compress images before uploading (use tools like TinyPNG or ImageOptim)
  • Use a plugin that offloads image processing to an external service
  • Increase memory limit specifically for admin operations: define( 'WP_MAX_MEMORY_LIMIT', '512M' );

4. WooCommerce or Large E-commerce Catalogs

How to confirm: WooCommerce stores with hundreds or thousands of products often hit memory limits during inventory syncs, report generation, or bulk operations.

Diagnosis steps:

  • Note if the error occurs during WooCommerce admin tasks (export, reports, bulk edit)
  • Check WooCommerce status for memory recommendations

The fix:

  • Set WooCommerce-specific memory limits in wp-config.php
  • Split large operations into smaller batches
  • Consider a Cloud VPS if you are on shared hosting—e-commerce stores benefit from dedicated resources

5. Server-Level PHP Memory Limit Too Low

How to confirm: If you have tried increasing WP_MEMORY_LIMIT but the error persists, the server-level memory_limit in php.ini may be overriding it.

Diagnosis steps:

  • Create a phpinfo.php file: <?php phpinfo(); ?>
  • Load it in your browser and search for “memory_limit”
  • If it is 64M or 128M and you need more, you will need to change it

The fix: On cPanel hosting, you can often change this via:

  • cPanel > Select PHP Version > Options — adjust memory_limit directly
  • .user.ini in your public_html: memory_limit = 256M
  • Contact your host — some limits are set at the server level and require support intervention

Diagnostic Flowchart

Not sure which cause applies? Follow this decision tree:

StepCheckIf YesIf No
1Did the error appear after a plugin update or new plugin?? Disable that plugin (Cause 1)? Go to Step 2
2Does the error occur only on specific pages?? Test with default theme (Cause 2)? Go to Step 3
3Is it happening during image uploads or media operations?? Optimise images, increase admin memory (Cause 3)? Go to Step 4
4Are you running WooCommerce with a large catalog?? Increase memory, consider VPS upgrade (Cause 4)? Go to Step 5
5Did increasing WP_MEMORY_LIMIT not help?? Check server-level php.ini (Cause 5)? Problem solved

Prevention: Keep It From Happening Again

Once you have fixed the immediate error, take these steps to prevent recurrence:

1. Set a Realistic Memory Limit

For most sites, 256MB is sufficient. For e-commerce or complex setups, 512MB is safer. Add both to wp-config.php:

define( 'WP_MEMORY_LIMIT', '256M' );     // Frontend
define( 'WP_MAX_MEMORY_LIMIT', '512M' ); // Admin area

2. Install Query Monitor

The free Query Monitor plugin shows exactly which plugins, themes, and database queries are consuming memory. Review it periodically, especially after adding new functionality.

3. Audit Plugins Regularly

Every 3-6 months, review your installed plugins. Deactivate and delete any you are not actively using. Each active plugin adds memory overhead.

4. Choose Quality Hosting

Budget hosts often set aggressive memory limits (32MB-64MB) to squeeze more customers per server. If you are consistently hitting memory walls despite optimisation, it may be time to upgrade. Our Shared Hosting plans include generous memory allocations, and our Cloud VPS gives you dedicated resources with full control over PHP settings.

When to Contact Support

Some scenarios require human intervention:

  • You cannot access wp-config.php or php.ini — some hosts restrict file editing
  • Increasing memory does not help — the root cause may be a database corruption or hacked file
  • The error is intermittent — hard to reproduce issues often indicate deeper problems
  • You are on shared hosting with strict limits — we can discuss upgrade options

At Canadian Web Hosting, our support team can investigate memory issues directly, adjust server-level PHP settings where appropriate, and recommend hosting upgrades if your site has outgrown its current plan. Contact us and we will take a look.

Related Issues and Further Reading