How to Diagnose WordPress Memory Limit Errors Without Hiding Them
A WordPress memory limit error means PHP ran out of memory while executing a request, and the fatal error names the file and line where the allocation failed. The limit is set by PHP's memory_limit directive, not by WordPress, so the fix belongs in PHP configuration at the host level, and the diagnosis belongs in the code that was running when the allocation failed.
The message usually looks like this:
Fatal error: Allowed memory size of 268435456 bytes exhausted
(tried to allocate 20480 bytes) in
/home/example/public_html/wp-includes/...
Read it carefully. The byte count before "exhausted" is your current limit. The number after "tried to allocate" is the size of the single allocation that tipped it over, which is often small. A small failed allocation means the process was already close to the ceiling, so the real consumer is whatever ran before that line, not the line itself.
Why the wordpress memory limit error appears
PHP allocates memory per request and frees it when the request ends. Every plugin, theme and core file loaded during that request shares one budget. A page that loads a large options row, builds a big query result, or runs an image operation can push a single request past the limit even when the average page is fine. That is why the error often appears on specific admin screens, on imports, or on a handful of front end URLs rather than everywhere.
WordPress also defines WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT in wp-config.php. These call ini_set() at runtime, but PHP will not let a script raise the limit above the host's ceiling in some configurations, and a host level cap silently wins. If you edit wp-config.php and nothing changes, the host is overriding you. That is a signal to fix the limit in PHP itself, not to add another constant.
Find what is actually consuming memory
Start by confirming the effective limit as PHP sees it, not as you believe it is set. Run this from the site root:
php -i | grep -E 'memory_limit|Loaded Configuration'
php -r 'echo ini_get("memory_limit"), PHP_EOL;'
The first line tells you which php.ini is loaded and what the limit is on the command line. The CLI limit can differ from the web limit, so also check the value the web server reports. A small PHP file that calls phpinfo() or ini_get('memory_limit') served over HTTP gives you the real number for web requests. Compare the two before changing anything.
To find the consumer, bisect. Deactivate plugins in groups and retest the failing URL after each change. When the error disappears, the culprit is in the group you just removed, and you narrow from there. For themes, switch to a default theme temporarily and retest. This is slow but reliable, and it does not require guessing.
For a faster read, log peak usage per request. Add a mu-plugin that records memory_get_peak_usage(true) at shutdown, or use a query monitor style plugin that shows peak memory per page load. The page that peaks highest is your target. Then look at what that page does: a large WP_Query with posts_per_page set to -1, an unbounded get_posts(), an image resize loop, or a plugin that loads an entire table into an array are common causes.
You can also trace allocations with a profiler if the host allows it. Xdebug's profiler output, or a sampling profiler, shows which functions allocate the most. That is heavier setup, but it answers the question directly instead of by elimination.
Raise the limit correctly at the host level
Once you know the real consumer, raise the limit in PHP configuration so the change applies to every request, including cron and admin. On a server you control, edit the relevant php.ini:
memory_limit = 512M
max_execution_time = 120
Reload PHP-FPM or the web server so the change takes effect, then recheck with php -i and over HTTP. If you use per site pools, set php_admin_value[memory_limit] in the pool configuration instead, which prevents scripts from overriding it. On shared hosting you usually cannot edit php.ini directly, so use the host's PHP settings panel or a .user.ini file in the site root:
memory_limit = 512M
Confirm it took effect before assuming it did. A .user.ini that the host ignores, or a pool setting that overrides it, will leave you chasing the same error.
Do not treat a plugin that raises the limit as a fix. Plugins that call ini_set('memory_limit', ...) only work when the host permits it, and they hide the underlying problem: a request that needs more memory than it should. Raising the ceiling is legitimate when a known operation genuinely needs it, such as a large import or an image batch. It is not legitimate as a permanent substitute for fixing an unbounded query or a plugin that loads too much data.
What to do next
Reproduce the error on a specific URL, read the fatal error for the current limit and the failed allocation size, and confirm the effective limit over HTTP as well as on the command line. Then bisect plugins and themes to find the request that peaks highest, and fix that code path before you raise the ceiling. Raise the limit in PHP configuration at the host level, verify it applied, and leave the plugin based workarounds out of the picture.
