I want to set WP_MEMORY_LIMIT for my WordPress site. I use from shared hosting and CPanel. I have access to change something like max memory limit on my host. I attached related image in the following that you can see it:
I checked max memory limit on host by a php file and phpinfo();
and it's set to 512M.
My problem is related to set WP_MEMORY_LIMIT
on wp-config.php
file. I add these line of code to define these constants in WordPress like this:
I have used from "Server IP & Memory Usage Display" which shows WP memory limit and WP max memory limit at the bottom of each admin panel pages. Strange thing is WP Max Memory limit is 512M but WP Memory limit has been 40M yet.
I searched for that in stack-overflow forums and I found that I should change it from default-constants.php
in wp-includes directory.
// 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' );
}
}
if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
} elseif ( -1 === $current_limit_int || $current_limit_int > 268435456 /* = 256M */ ) {
define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
} else {
define( 'WP_MAX_MEMORY_LIMIT', '256M' );
}
}
I changed it and it works correctly but it's not a right way because every time I update WordPress, it'll change to 40M again and I have to change it manually again from default-constants.php
.
So How can I solve this issue? Why didn't it apply and work in wp-config?