Using WordPress ‘admin_memory_limit’ PHP filter

The admin_memory_limit WordPress PHP filter adjusts the maximum memory limit available for administration screens.

Usage

add_filter('admin_memory_limit', 'my_custom_admin_memory_limit');
function my_custom_admin_memory_limit($filtered_limit) {
    // your custom code here
    return $filtered_limit;
}

Parameters

  • $filtered_limit (int|string): The maximum WordPress memory limit. Accepts an integer (bytes), or a shorthand string notation, such as ‘256M’.

More information

See WordPress Developer Resources: admin_memory_limit

Examples

Increase admin memory limit to 512M

This example increases the admin memory limit to 512 megabytes.

add_filter('admin_memory_limit', 'increase_admin_memory_limit');
function increase_admin_memory_limit($filtered_limit) {
    return '512M';
}

Decrease admin memory limit to 128M

This example decreases the admin memory limit to 128 megabytes.

add_filter('admin_memory_limit', 'decrease_admin_memory_limit');
function decrease_admin_memory_limit($filtered_limit) {
    return '128M';
}

Double the admin memory limit

This example doubles the current admin memory limit.

add_filter('admin_memory_limit', 'double_admin_memory_limit');
function double_admin_memory_limit($filtered_limit) {
    $bytes = wp_convert_hr_to_bytes($filtered_limit);
    return 2 * $bytes . 'B';
}

Set admin memory limit to a percentage of total server memory

This example sets the admin memory limit to 50% of the total server memory.

add_filter('admin_memory_limit', 'percentage_of_total_memory');
function percentage_of_total_memory($filtered_limit) {
    $total_memory = intval(ini_get('memory_limit'));
    $half_memory = $total_memory * 0.5;
    return $half_memory . 'M';
}

Reset admin memory limit to the original value

This example resets the admin memory limit to the original PHP memory_limit value.

add_filter('admin_memory_limit', 'reset_admin_memory_limit');
function reset_admin_memory_limit($filtered_limit) {
    return ini_get('memory_limit');
}