Recommended Services
Supported Scripts
WordPress not using PHP.ini memory limit — fix with WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT in wp-config.php

A common frustration on WordPress hosting setups is increasing memory_limit in php.ini only to find WordPress still reports the old memory value. This happens because WordPress defines its own internal memory cap that overrides whatever PHP.ini says. There are three correct places to set the WordPress memory limit — this guide explains all of them and which takes priority.

Why PHP.ini Changes Don’t Always Work in WordPress

WordPress sets its own memory limits in wp-includes/default-constants.php. When WordPress bootstraps, it calls ini_set('memory_limit', WP_MEMORY_LIMIT) — which overrides the PHP.ini value at runtime. So even if your PHP.ini says memory_limit = 512M, WordPress may cap itself at its own default of 40M (front-end) or 256M (admin).

The Correct Priority Order

WordPress checks memory limit values in this order — the first defined value wins:

  1. WP_MEMORY_LIMIT defined in wp-config.php (highest priority — recommended method)
  2. memory_limit set in a .htaccess file (Apache only)
  3. memory_limit set in php.ini or php.ini override files
  4. WordPress default constants in wp-includes/default-constants.php (lowest — never edit this file directly)

Method 1: Set Memory Limit in wp-config.php (Recommended)

This is the correct and upgrade-safe method. Open wp-config.php and add both constants before the /* That's all, stop editing! */ line:

// Memory available to WordPress front-end
define( 'WP_MEMORY_LIMIT', '256M' );

// Memory available to WordPress admin/back-end (should be >= WP_MEMORY_LIMIT)
define( 'WP_MAX_MEMORY_LIMIT', '512M' );

Important: WP_MAX_MEMORY_LIMIT controls memory in the WordPress admin dashboard (used by media uploads, plugin/theme installation, etc.) and should be set equal to or higher than WP_MEMORY_LIMIT. It cannot exceed the hard cap set in php.ini.

Method 2: Set Memory Limit in .htaccess (Apache)

If your server uses Apache with mod_php, you can set the PHP memory limit directly in your site’s .htaccess file:

php_value memory_limit 256M

Note: This method does not work on Nginx or PHP-FPM setups — use wp-config.php instead.

Method 3: Set Memory Limit in php.ini

On cPanel servers, you can set PHP memory via a per-directory php.ini or .user.ini file in your WordPress root. This sets the PHP hard cap that WordPress cannot exceed:

memory_limit = 512M

On cPanel, you can also change this via cPanel → Select PHP Version → PHP Options → memory_limit without editing files manually.

Verify the Active Memory Limit

After making changes, verify what memory limit WordPress is actually using. Add this temporarily to any WordPress template or use the Health Check plugin:

// Add temporarily to functions.php or a plugin — remove after testing
echo 'WP Memory Limit: ' . WP_MEMORY_LIMIT . '
'; echo 'PHP Memory Limit: ' . ini_get('memory_limit') . '
'; echo 'Memory In Use: ' . size_format(memory_get_usage()) . '
';

Alternatively, go to WordPress Admin → Tools → Site Health → Info → Server to see the current PHP memory limit without writing any code.

Recommended Values by Use Case

Site TypeWP_MEMORY_LIMITWP_MAX_MEMORY_LIMIT
Small blog / brochure site128M256M
Standard business site with plugins256M512M
WooCommerce / heavy plugins512M512M
Large multisite / page builders512M1024M