Sysadmins of the North
Share now!

Set WP_MEMORY_LIMIT value correctly in wp-config.php

WordPress developers: please stay away from WP_MEMORY_LIMIT and PHP memory_limit settings! We see this done wrong over and over in WordPress plugins and themes. One of such themes is the premium theme Jupiter by Artbees, or WPML as plugin. WordPress users: don’t touch these memory limitation settings either! They’re imposed for a reason. Here’s some explanation:

In a situation where PHP memory_limit is set higher than WP_MEMORY_LIMIT this may cause problems.

TL;DR: use define( 'WP_MEMORY_LIMIT', ini_get( 'memory_limit' ) ); to set the memory limit to your current PHP memory_limit. If necessary you can increase the limit in an user-defined .ini file.

Before we continue, it’s nice to know what WP_MEMORY_LIMIT (and WP_MAX_MEMORY_LIMIT) is used for.

WordPress writes on the Codex:

Also released with Version 2.5, the WP_MEMORY_LIMIT option allows you to specify the maximum amount of memory that can be consumed by PHP. This setting may be necessary in the event you receive a message such as “Allowed memory size of xxxxxx bytes exhausted”.

This setting increases PHP Memory only for WordPress, not other applications. By default, WordPress will attempt to increase memory allocated to PHP to 40MB (code is at the beginning of /wp-includes/default-constants.php) for single site and 64MB for multisite, so the setting in wp-config.php should reflect something higher than 40MB or 64MB depending on your setup.

WordPress will automatically check if PHP has been allocated less memory than the entered value before utilizing this function. For example, if PHP has been allocated 64MB, there is no need to set this value to 64M as WordPress will automatically use all 64MB if need be.
Please note, this setting may not work if your host does not allow for increasing the PHP memory limit–in that event, contact your host to increase the PHP memory limit. Also, note that many hosts set the PHP limit at 8MB.

WordPress Codex – Increasing memory allocated to PHP

Now imagine your PHP memory_limit is set to 134 MB.

This may interest you:   Install Varnish Cache on CentOS 6.7

Note: the mentioned themes and plugins are just examples, this is not a rant towards them. Have you ever needed to set a different memory limit, and why?

The aforementioned theme has the following PHP code snippet in wp-content/themes/jupiter/framework/admin/control-panel/logic/compatibility.php:

public function phpIniCheck()
	// ...
	$incorrect_memory_limit        = ($this->let_to_num(WP_MEMORY_LIMIT) < 100663296);
	// ...
	if ($incorrect_memory_limit)
		$response[] = [
			'sys_msg'       => __('WordPress Memory Limit', 'mk_framework') . ': ' . WP_MEMORY_LIMIT . ', ',
			'sys_recommend' => __('memory_limit should be at least 96MB.', 'mk_framework'),
			'link_href'     => '',
			'link_title'    => __('Increasing memory allocated to PHP', 'mk_framework'),
			'type'          => 'error',
			'status'        => false,
	// ...

The function let_to_num() is found in wp-content/themes/jupiter/framework/admin/control-panel/logic/functions.php.

This function phpIniCheck() checks whether WP_MEMORY_LIMIT is defined and set high enough: more than 96 MB. If that’s not the case, show an error. It’s the check for WP_MEMORY_LIMIT that’s used wrong here.

How WordPress defines memory limits

WordPress defines and sets memory limits in the file ./wp-includes/default-constants.php, on lines 32 – 44 (source:

$current_limit     = @ini_get( 'memory_limit' );
$current_limit_int = wp_convert_hr_to_bytes( $current_limit );

// Define memory limits.
if ( ! defined( 'WP_MEMORY_LIMIT' ) ) {
	if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
		define( 'WP_MEMORY_LIMIT', $current_limit );
	} elseif ( is_multisite() ) {
		define( 'WP_MEMORY_LIMIT', '64M' );
	} else {
		define( 'WP_MEMORY_LIMIT', '40M' );

The PHP resource limit memory_limit is changeable in PHP_INI_ALL, meaning it can be set (changed) anywhere – normally. This should return true for wp_is_ini_value_changeable( 'memory_limit' ).

This defines WP_MEMORY_LIMIT as 40M as lower limit – for a single site installation, when memory_limit may be changed.

This may interest you:   Remove Jetpack email sharing service

And back to the Jupiter theme. Take a look at the phpIniCheck() function. Here’s the logic of what it does:

  1. is WP_MEMORY_LIMIT defined and smaller than 100663296 bytes (96 MB)?
  2. throw an error

We’ve just learned that normally WP_MEMORY_LIMIT is defined to a lower limit of 40M, because memory_limit may be changed anywhere by PHP, and then wp_is_ini_value_changeable returns true.

The check Artbees/Jupiter uses, checks if the 40M WP_MEMORY_LIMIT is lower than 96M (100663296 bytes). The check evaluates as $true, setting the variable $incorrect_memory_limit to true, and the error message is displayed.

Pff… Someone really needs to look at this WP_MEMORY_LIMIT logic in WordPress… Because and there is WP_MAX_MEMORY_LIMIT…

In short, the difference between WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT is:

This setting [WP_MEMORY_LIMIT] increases PHP Memory only for WordPress, not other applications. By default, WordPress will attempt to increase memory allocated to PHP to 40MB (code is at the beginning of /wp-includes/default-constants.php) for single site and 64MB for multisite, so the setting in wp-config.php should reflect something higher than 40MB or 64MB depending on your setup.

Administration tasks require much memory than usual operation. When in the administration area, the memory can be increased or decreased from the WP_MEMORY_LIMIT by defining WP_MAX_MEMORY_LIMIT.

So WP_MEMORY_LIMIT is the limit and WP_MAX_MEMORY_LIMIT, if set, will override the former in the admin.

This may interest you:   WordPress 3.5 on IIS 8.0 is unable to save a web.config file


You mentioned WPML? Yes I did.

In sitepress-multilingual-cms/classes/troubleshoot/class-wpml-debug-information.php WPML inaccurately assumes WP_MEMORY_LIMIT is the current imposed memory limit:

function get_core_info() {

	$core = array(
		// ...
		'PHP'       => array(
			'MemoryLimit'     => ini_get( 'memory_limit' ),
			'WP Memory Limit' => WP_MEMORY_LIMIT,
			'UploadMax'       => ini_get( 'upload_max_filesize' ),
			'PostMax'         => ini_get( 'post_max_size' ),
			'TimeLimit'       => ini_get( 'max_execution_time' ),
			'MaxInputVars'    => ini_get( 'max_input_vars' ),
			'MBString'        => $this->sitepress->get_wp_api()->extension_loaded( 'mbstring' ),
			'libxml'          => $this->sitepress->get_wp_api()->extension_loaded( 'libxml' ),

	return $core;

If you want to increase WP_MEMORY_LIMIT, do it properly in your wp-config.php file

The fix for all this is quite easy. But only do this if plugins/themes won’t work properly otherwise!

Define WP_MEMORY_LIMIT in your wp-config.php file, and set it to your current PHP memory_limit:

define( 'WP_MEMORY_LIMIT', ini_get( 'memory_limit' ) );

Add the above line just before the line “/* That’s all, stop editing! Happy blogging. */“.

Setting this constant may throw a PHP Notice when put below this line. The PHP Notice is for example (on one line):
PHP Notice:  Constant WP_MEMORY_LIMIT already defined in
/path/to/ on line 96

As always, it’s best to trust your hosting provider and to not fiddle with memory settings. WordPress loving hosting providers -like– will set reasonable limitations, as you may expect. So your WordPress website always runs as smooth as possible.

If you are a WordPress plugin or theme developer: Please stay away from fiddling with PHP/WordPress memory limits. If you are a WordPress user: don’t fiddle with PHP/WordPress memory settings either!

Questions? Remarks? Leave them as a comment please, thanks!

buy me a coffee
Buy Me A Coffee

About the Author Jan Reilink

My name is Jan. I am not a hacker, coder, developer, programmer or guru. I am merely a system administrator, doing my daily thing at Vevida in the Netherlands. With over 15 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, WordPress, websites & optimization. Want to support me and donate? Use this link:

follow me on:

Thank you!

Leave a Comment:

1 comment
Add Your Reply
Skip to content