How to Increase The Memory Size Limit On Your WordPress Site

How to Increase The Memory Size Limit On Your WordPress Site

Sometimes your WordPress site will max out the ‘Memory Size Limit’ and your site will break and not display normally. You can fix this by making some alterations to your WordPress site code or server settings within several minutes. In this article I will show you how to do these to achieve a fix to this issue.

Table of Contents

What is ‘Memory Size Limit’ in your WordPress Site

Your website files lives on a physical server computer that is owned by your host company (or perhaps rented). This physical computer, just like your laptop, phone or desktop, has a certain amount of RAM. RAM is the kind of memory your site uses to ‘do’ various tasks and has sometimes been associated with the metaphor of ‘multi tasking‘ in day to day human life. The higher your amount of RAM the more data you can deal with on your WordPress site in one process. A bit like someone who can multi-task can deal with a lot of tasks.

If your site is doing a lot of processing of data or has a lot of users on it then this takes up RAM Memory and if there is too many processes running or if there is too many people on the site then the limit can be reached and your WordPress site can stop running. This often means that your users will not be able to load your site whatsoever.

How to increase ‘Memory Size Limit’

There are several places to edit the max RAM or memory size so you need to make sure you have checked in a few places before you have successfully increased the limit.

Alter ‘Memory Size Limit’ in wp-config.php

In the root of your site you will find this file at https://yoursite.com/wp-config.php. You will need to access this through the File Manager on your cPanel because this is not editable from the WordPress CMS itself.

  • You can find the cPanel on your hosting Dashboard.
cPanel on your dashboard. Look for the File Manager.
  • Look for the File Manager Dashboard.
  • Look for the root folder for your site.
  • This could be in the public_html file commonly or perhaps in a folder like yoursite.com.
This is what File Manager looks like when you have clicked into it.
  • The file structure can differ based on the server host you have but the above are common folders to look for.
  • Directly inside of this folder you will find the wp-config.php
  • Click to edit it.
  • At the bottom of the file add the below code.
define( ‘wp_memory_limit’, ‘512M’ );

In the above example we are telling WordPress to use 512 MB as the maximum RAM memory. You can change the ‘512’ to any number and can go higher if you need for eg,

define( ‘wp_memory_limit’, ‘1024M’ );

Alter ‘Memory Size Limit’ on the server

There can also be server level setting controlling the Memory Limit. These are usually accessible through the cPanel on your host dashboard but could differ in exact access depending on your particular host. On Bluehost you can look for the ‘Multi PHP INI Editor‘ icon and edit the Memory settings from here.

Once you’re inside of that file you will see it next to the heading ‘memory_limit’.

Alter ‘Memory Size Limit’ in the code

If you are wanting to up the memory size for a particular function or hook only and not for the entire website then you could also up the memory limit with PHP.

You can insert this line into your application code in order to do that.

ini_set('memory_limit', '512MB');
// alter the '512' to be as high or low as you like

Trouble Shooting ‘Memory Size Limit’

Because there are multiple places to change or increase the memory limit it can be sometimes difficult to find all the places and make sure one of them is not ‘undercutting’ the maximum limit. Thats’ why I’ve tried to show you a few different ways so that you can check each and make them all the maximum limit. Otherwise it’s possible to change it in one location and think you’ve correctly done so but then still find the same issue as some other setting is not increased to your desired maximum.

Note that increasing the memory limit is also not always a long term fix as applications which are greedy on data or sites which have an influx of users can often reach the newly created max. If this is the case changing the memory limit is a short term fix and the permanent fix is to fix the root cause. For eg, if your application is too greedy on data then perhaps that can be redesigned to show the data in smaller chunks – think a form which allow users to load data by date or something smaller instead of all of it.

Also it could be worth upgrading your hosting plan if there are too many users on the site. I use Bluehost so if you are after a new host that works well with WordPress then this may be the ticket.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *