How to fix WordPress memory limit errors

How to fix WordPress memory limit errors

Sometimes when installing or using themes and plugins in WordPress, you might run into errors related to the memory limit assigned to PHP. Some common messages include:

  • Allowed memory size of xxx bytes exhausted...
  • Fatal error: Out of memory...

These errors mean that WordPress has reached the allowed memory limit and needs more resources to function properly. Fortunately, you can fix this by editing a key file: wp-config.php.


What is memory_limit and why are there two values?

In WordPress, there are two important memory settings you can define:

  • WP_MEMORY_LIMIT: Sets how much memory WordPress can use for site visitors (frontend).
  • WP_MAX_MEMORY_LIMIT: Sets how much memory WordPress can use in the admin area (backend).

This allows the admin panel to run heavier tasks, such as installing themes or updating plugins, without affecting performance for regular site visitors.


How to adjust the memory_limit in wp-config.php?

Follow these steps to make the change:

1. Log in to your cPanel

Go to your cPanel at https://cpanel.yourdomain.com and log in with your username and password.

2. Open the File Manager

From the cPanel dashboard, go to File Manager and navigate to the folder where WordPress is installed (usually the public_html folder).

3. Edit the wp-config.php file

  1. Locate the file named wp-config.php.
  2. Right-click on it and select Edit.
  3. Inside the file, add the following two lines at the end:
define('WP_MEMORY_LIMIT', '128M');
define('WP_MAX_MEMORY_LIMIT', '256M');

Note: You can adjust the values based on your site's needs. For example, 256M or even 512M if you're running heavy tasks and your hosting plan allows it.


When will the changes take effect?

Changes take effect immediately. You can reload your site or retry the action that triggered the error. If the issue persists, your hosting account might have a server-level limit. In that case, feel free to contact us so we can investigate and help you resolve it.


Recommendations

  • Avoid using excessive values without reason (e.g., 1024M), as it may negatively impact your hosting account's performance.
  • If you're on a shared hosting plan, consider optimizing your plugins and themes before increasing the memory limit.
  • Always back up your site before editing system files.