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 a custom WP_MEMORY_LIMIT in wp-config.php, this may cause problems.

TL;DR: use define( 'WP_MEMORY_LIMIT', ini_get( 'memory_limit' ) ); in wp-config.php 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 are 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 web server’s PHP memory_limit is set to 134 MB.

You may find this post interesting too:   HackRepair.com's Bad Bots .htaccess in web.config for IIS

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? Why? Let me know in the comments, thanks!

The Jupiter 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'     => 'http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP',
			'link_title'    => __('Increasing memory allocated to PHP', 'mk_framework'),
			'type'          => 'error',
			'status'        => false,
	// ...

The function let_to_num() is located 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: https://github.com/WordPress/WordPress/blob/master/wp-includes/default-constants.php):

$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.

You may find this post interesting too:   WordPress advisory: Akal premium theme XSS vulnerability

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… And 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.


You mentioned WPML? Yes I did.

You may find this post interesting too:   Display commas in WordPress tags

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/example.com/www/wp-config.php 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 Vevida.com– will set reasonable limitations, as you may expect. So your WordPress website always runs as smooth as possible.

WordPress plugin and theme developers: 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