2

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:

enter image description here

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:

enter image description here

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?

  • can you try to paste both lines directly below WP_DEBUG line – Piyush Rawat Nov 16 '17 at 10:57
  • It's prefect answer, I changed it and paste it directly below WP_DEBUG line . I didn't know that the order in wp-config.php is important. Many thanks for your perfect answer. Thank you a lot – Mehdi Soltani Nov 16 '17 at 11:05
  • Ok. I'll post it as answer – Piyush Rawat Nov 16 '17 at 11:08
4

Need to set both the constants before ABSPATH is defined. Right after this line in wp-config.php

define( 'WP_DEBUG_LOG', true );
  • mark the answer as accepted for future users – Piyush Rawat Nov 16 '17 at 11:10
  • Dear Piyush,How can I mark this as accepted answer? – Mehdi Soltani Nov 16 '17 at 11:13
  • There would be a checkmark on left side of the answer – Piyush Rawat Nov 16 '17 at 11:14
0

Just 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. */“.

2

This is because you should define the above before /* That's all, stop editing! Happy blogging. */

Like this:

define('WP_MEMORY_LIMIT', '256M');
define('WP_MAX_MEMORY_LIMIT', '512M');

/* That's all, stop editing! Happy blogging. */

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.