It happens to all WordPress site owners and administrators eventually: The dreaded WordPress memory error.
You鈥檙e minding your own business adding new content or media to your site when suddenly a message pops up: 鈥淔atal error: Allowed memory size of xxxxxx bytes exhausted.鈥
What just happened? Why did WordPress run out of memory?
Put simply, it comes down to the programming language PHP. WordPress sites use a default memory limit for PHP code which can be exceeded as you start adding more media-rich and interactive elements to your site.
In this piece, we鈥檒l break down what the WordPress PHP memory limit is, why it matters for your site, and what you can do to increase it.
PHP is a server-side language used by WordPress to create and manage the HTML pages that make up your site. It鈥檚 called 鈥渟erver-side鈥 because it operates in the WordPress backend, not on your desktop computer or mobile device.
PHP is a lightweight, speedy, and open-source language that鈥檚 ideal for generating website elements. Experienced programmers can customize or modify PHP frameworks to suit specific website needs, and the code is regularly updated to streamline functionality and enhance security. As a result, it鈥檚 an ideal general-purpose scripting language for WordPress.
By default, WordPress has a PHP memory limit of 32MB. That鈥檚 fine for sites with few pages and a limited amount of multimedia content and plugins, but the more you add to your site the closer you get to the maximum memory limit.
When this limit is reached 鈥 let鈥檚 say you鈥檙e uploading a new video or interactive web element 鈥 WordPress will automatically increase available memory to 40MB. If you still hit the limit, you鈥檒l get the error message described above and won鈥檛 be able to add new content until you resolve the issue.
While it is possible to increase the available PHP memory in WordPress beyond 40MB, it鈥檚 worth pinpointing the cause of memory max-outs before taking action to up your limit. Here鈥檚 why: If the root cause of your memory issue isn鈥檛 simply available space but something tied to other elements on your site, adding more memory is only a temporary fix 鈥 the problem will persist and you鈥檒l keep getting the same error.
Some possible causes of memory limit issues include:
Not all plugins are created equal. Some are built for speed and quality, while others are designed to perform a specific function but don鈥檛 make any effort to improve efficiency. Using multiple plugins with high memory requirements can max out available PHP memory and cause your page to suffer a fatal error.
As noted by , 61.6% of WordPress sites are running outdated versions of PHP. Not only does this present a security risk for sites but it also impacts their performance. Newer versions of PHP are capable of handling more tasks, more quickly, in turn reducing the amount of memory in use at any given time.
What you put on your site matters for memory. For example, if your WordPress site is largely composed of text with the occasional image and link, you probably won鈥檛 hit the memory limit. If you鈥檙e consistently uploading videos and other interactive content, you may find yourself running out of room.
What if you鈥檙e not sure what鈥檚 causing the problem? Get a plugin like that tracks the memory usage and total available memory of your WordPress installation and shows the version of PHP you鈥檙e currently running. Visual cues highlight increasing memory usage 鈥 as memory usage ramps up, the percentage value slowly changes to red, letting you know you鈥檙e reaching the limit. The plugin also shows how much memory other plugins are using to help you pinpoint memory thieves.
But, should you maximize your memory bandwidth and push WordPress to its limit? Or, is it better to stay below the memory limit for better site performance? Let鈥檚 discuss in the section below.
WordPress has a 32MB memory limit by default, but some hosting providers increase this to 64MB for all customers. It鈥檚 also possible to go even bigger 鈥 all the way up to 256MB.
While scaling allows more room for content and media, it does come with the potential drawback of slower site speeds if you implement a host of data-heavy elements. Best bet? Try to land somewhere in the middle to balance memory throughput and performance.
If you鈥檝e updated your PHP, removed poor-quality plugins, cleaned up your content, and you鈥檙e still getting memory errors, you may need to increase the memory limit.
There are several ways to accomplish this goal:
If you鈥檙e reasonably confident in your tech skills, you could try editing your wp-config.php file.
First up? Getting to it. Use a file transfer protocol (FTP) or SSH file transfer protocol (SFTP) service to connect with and access your WordPress files. Your mileage will vary depending on the solution you use, but you should see something like this:
Open the wp-config.php file and search for this text string: define('WP_MEMORY_LIMIT', '32M');
Then, modify it to read define('WP_MEMORY_LIMIT', '128M'); You can go as high as 256MB, but in most cases, you won鈥檛 need this much memory.
If editing your config file doesn鈥檛 solve the problem, you can also try modifying your PHP.ini file. Worth noting? Since this file governs server settings, you won鈥檛 be able to modify it if you鈥檙e using a shared hosting provider.
Look for the line memory_limit = 32M and again change it to read 128M. It鈥檚 also a good idea to modify the max_execution_time line. This line specifies the amount of time in seconds allotted for a PHP script to run. If the time limit is exceeded, PHP returns an error. Increasing this number gives your scripts more time to run, which is a good idea if you鈥檙e planning to use more memory-intensive services and plugins.
Your last file editing resort is the .htaccess file. While it is accessible via the directory and file list returned by FTP connections, the 鈥.鈥 in front means that it鈥檚 a hidden file. If you don鈥檛 see it, check to make sure your FTP or SFTP solution is set to display all hidden files and directories.
Once you鈥檝e accessed the file, find this line: php_value memory_limit Then, add the value you want 鈥 64M, 128M, or 256M 鈥 and save the file.
Regardless of the file editing method you choose, make sure to clear your cache before checking to see if the problem is resolved.
Another option to increase your available PHP memory is through the use of a plugin, such as the . This plugin works with WordPress version 5.2 or higher and lets you modify available PHP memory without the need to access or modify files.
Last but not least? Contact your hosting provider and ask them to increase your WordPress PHP memory limit. Depending on the type of hosting you have 鈥 shared, dedicated, or virtual private server 鈥 this may be a quick fix or it may not be a service offered.
PHP memory errors in WordPress are frustrating, but they aren鈥檛 permanent. By modifying your WordPress files, using a plugin, or contacting your hosting provider, it鈥檚 possible to significantly increase your available memory and avoid PHP problems.