Beginner's Guide for WordPress / Start your WordPress Blog in minutes

Fix: WordPress Memory Exhausted Error – Increase PHP Memory

Are you seeing an allowed memory size exhausted error message in WordPress?

This is one of the most common WordPress errors, and you can easily fix it by increasing the PHP memory limit in WordPress.

In this article, we will show you how to fix the WordPress memory exhausted error by increasing the PHP memory limit.

Fix: WordPress Memory Exhausted Error – Increase PHP Memory

What Is the WordPress Memory Exhausted Error?

WordPress is written in PHP, which is a server-side programming language. Additionally, every website needs a WordPress hosting server for it to function properly.

Web servers are just like any other computer. They need memory to efficiently run multiple applications at the same time. Server administrators allocate specific memory size to different applications, including PHP.

When your WordPress code requires more memory than the default allocated memory, you will see this error message:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2348617 bytes) in /home4/xxx/public_html/wp-includes/plugin.php on line xxx

Memory exhausted error displayed on a WordPress site

By default, WordPress automatically tries to increase the PHP memory limit if it is less than 64MB. However, 64MB is often not high enough.

Having said that, let’s see how to easily increase the PHP memory limit in WordPress to avoid the memory exhausted error.

Increase the PHP Memory Limit in WordPress

First, you need to edit the wp-config.php file on your WordPress site. It is located in your WordPress site’s root folder, and you will need to use an FTP client or file manager in your web hosting control panel.

Next, you need to paste this code in the wp-config.php file just before the line that says, ‘That’s all, stop editing! Happy blogging.’

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

This code tells WordPress to increase the PHP memory limit to 256MB.

Once you are done, you need to save your changes and upload your wp-config.php file back to your server.

Alternatively, you can use WPCode to insert this code snippet. It is the best WordPress code plugin that allows you to insert code snippets into your site’s files without editing them directly.

For more details, please see our guide on how to easily add custom code in WordPress.

You can now visit your WordPress site, and the memory exhausted error should have disappeared.

We also have a step-by-step guide on how to find and edit the wp-config.php file.

Note: If this solution does not work for you, then this means your web hosting service provider does not allow WordPress to increase the PHP memory limit. This is common if you are using shared hosting. You will need to ask your web hosting provider if they can increase your WordPress memory limit manually.

We hope this article helped you solve the WordPress memory exhausted error by increasing the PHP memory limit. You may also want to see our step-by-step beginner’s guide to troubleshooting WordPress errors, along with our expert picks for the best WordPress plugins to grow your site.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

453 CommentsLeave a Reply

  1. define( ‘WP_MEMORY_LIMIT’, ‘256M’ ); worked all time. Thank a lot for the solution.

  2. you guys are amazing you solved most of the issues i encounter since started working with WordPress.

  3. Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 22 bytes) in /home/nels1max/public_html/ngifts/wp-includes/class-wp-hook.php on line 286

    I’ve tried to expand my limit but it didn’t work. When I refresh the page, it changes what’s after “/wp-includes/” and the line number, but none of those files have a place to expand the size. Any tips?

    • Try increasing it to 512M. There still isn’t enough memory for whatever theme you’re running. Good luck! P.S. make sure that you have more than 512M of memory. Ask your hosting provider.

  4. It works! Thanks for the suggestion. But I have a question. I find another article said that changes WP_MEMORY_LIMIT in default-constants.php. Is there any different between this two methods?

      • The constants file is for settings that don’t change, editing the config file is where you would make changes that can be reverted later when you are no longer receiving the error.

        Admin

  5. I looked everywhere for a solution and even called the host searching for an answer. Fixed it PERFECTLY! Thanks so very much!

  6. Dear All,

    we are getting this error
    let me know the solution on it?

    Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 8192 bytes) in /home/f036v20tz3th/public_html/wp-includes/functions.php on line 5276

    Regards
    KARTIK

  7. Thanks so much guys for this article! What is the diference from changing wp_memory_limit (wp-config.php) and memory_limit (php.ini)??? Are the same??
    This memory limit is for individual sessions or entire wordpress site?? I ask because if i had 200 visitors in minutes.. i have to go damn higher with this number?? Or try to keep it low??? Hope you can help me with this!

  8. Thank you guys so much for this! I spent the last couple hours trying to figure this out.

    Thanks again!

  9. When I changed with 512 M it was failed then I put it define( ‘WP_MEMORY_LIMIT’, ‘2000M’ );
    And it works well.
    /* That’s all, stop editing! Happy blogging. */ :-)

  10. if that code doesn’t work, rephrase it to

    //increase WP Memory Limit
    define(‘WP_MEMORY_LIMIT’, ‘256M’);

    • worked like a charm and loads faster .. but sure would like to knw the root cause and fix the issue there

    • you can change but it maxed out the memory and gave frequent errors of the same, editing posts on wordpress.com also had errors and tags and categories did not populate there.
      in WP it seems to work but it lagged considerably.
      If you have more memory allocated then you can do it. I am gonna do half of memory allocated by hosting. check cpanel for that.

  11. Thank you so much! I’ve been waiting for my developer to respond in order to fix it when I could have just done it myself! So much time wasted, thank you for publishing this!!

  12. You ROCK! Easy to follow and it worked! I am web-illiterate and was able to fix it in one go. THANK YOU!

  13. Thanks a lot for this article. It really helped me out. I was able to fix this problem and get onto building my site.

  14. Before doing any of this…be sure to check your root install directory. I had a blank ‘index.htm’ file that was left by my hosting service, and I completely overlooked it.

  15. Thank you so much for posting this tutorial! It fixed my website so I could start breathing again!

  16. You are rocking men…

    Every time I got an problem, I got it solution from here…

    Thanks for the awesome article.

  17. Thank you!!!! This was a Godsend!!! While trying to troubleshoot why some emails are not being sent via our online form, I installed a plugin and it caused this error. My web site is back up and running!!!! Thank you again!

  18. That fixed a number of problems! Being able to change themes; being able to save my widgets – great tip! Spent a lot of time looking for this solution.

  19. this doesn’t resolve my issue :( plz now tell me what I can do ?
    still error is there

    Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 4114136611 bytes) in C:\xampp\…\wp-includes\functions.php on line 5163

    • I get this error quite often. And I am not sure why.

      It comes from the function wp_is_stream(). I’m not sure where this is being used that is causing the error.

      A bit of investigation showed that if you comment out wp_head() in your header.php file that solves the issue. More specifically, it is something hooked onto the ‘wp_head’ action, and I think one of the filters with priority of 10. Unfortunately, after getting this far, the error magically fixed itself and went away, so I wasn’t able to track down the exact function. Also, wp_is_stream() was only used in 3 or 4 places, so maybe you could find the culprit easier just by checking the usages of that function.

  20. This was amazing. I was skeptical at first since this was my first time ever doing something like this. I finally just went for it and it worked. Thank you so much.

Leave a Reply to Emily Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.