Development

Fixing “Allowed memory size exhausted” in WordPress

The full error usually reads: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate …). That number is your PHP memory limit in bytes — 134217728 is 128M. A process needed more than the ceiling and PHP killed it. There are two things to do: lift the ceiling, and work out why it was hit.

1. Raise the limit in wp-config.php

Add this above the /* That’s all, stop editing! */ line in wp-config.php:

  • define('WP_MEMORY_LIMIT', '256M'); — the front-end limit
  • define('WP_MAX_MEMORY_LIMIT', '256M'); — the admin limit

Reload the page. If the error is gone, you are done — but read the last section, because a jump from 128M to 256M is normal, and needing 1G is not.

2. If that does not work, the host caps it

WordPress cannot raise memory above what the server allows. If wp-config.php has no effect, set it at the PHP level:

  • php.ini: memory_limit = 256M
  • .htaccess (Apache): php_value memory_limit 256M

On managed or shared hosting you often cannot edit these directly — raise it from the control panel or ask support. Confirm the active value in Tools → Site Health → Info → Server.

3. Find what is actually eating the memory

If you keep raising the limit and keep hitting it, the number is a symptom, not the problem. Common culprits:

  • A poorly written plugin loading huge datasets into memory at once.
  • An import, backup or export process on a large site — these legitimately need more, but only while running.
  • An unindexed query pulling tens of thousands of rows.

Install Query Monitor and watch memory usage per page, or deactivate plugins in halves to isolate the one responsible. Fixing the cause is better than feeding it more memory forever.

A sensible ceiling

256M covers the vast majority of sites, including WooCommerce stores and page builders. If a normal page load genuinely needs 512M or more, treat that as a bug to investigate rather than a setting to keep increasing.