Using WordPress ‘editor_max_image_size’ PHP filter

The editor_max_image_size WordPress PHP filter allows you to modify the maximum image size dimensions for the editor.

Usage

add_filter('editor_max_image_size', 'your_custom_function', 10, 4);
function your_custom_function($max_image_size, $size, $context) {
    // your custom code here
    return $max_image_size;
}

Parameters

  • $max_image_size (int[]): An array of width and height values (in pixels).
  • $size (string|int[]): Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).
  • $context (string): The context the image is being resized for. Possible values are ‘display’ (like in a theme) or ‘edit’ (like inserting into an editor).

More information

See WordPress Developer Resources: editor_max_image_size

Examples

Limit Maximum Image Size for Editor

Limit the maximum image size to 800×600 pixels when inserting into an editor.

add_filter('editor_max_image_size', 'limit_editor_max_image_size', 10, 4);
function limit_editor_max_image_size($max_image_size, $size, $context) {
    if ($context === 'edit') {
        $max_image_size = array(800, 600);
    }
    return $max_image_size;
}

Adjust Maximum Image Size Based on Context

Adjust the maximum image size based on the context of the image.

add_filter('editor_max_image_size', 'adjust_max_image_size_based_on_context', 10, 4);
function adjust_max_image_size_based_on_context($max_image_size, $size, $context) {
    if ($context === 'edit') {
        $max_image_size = array(1200, 900);
    } elseif ($context === 'display') {
        $max_image_size = array(1600, 1200);
    }
    return $max_image_size;
}

Limit Maximum Image Size for a Specific Image Size Name

Limit the maximum image size to 800×600 pixels when the requested image size is ‘large’.

add_filter('editor_max_image_size', 'limit_specific_image_size', 10, 4);
function limit_specific_image_size($max_image_size, $size, $context) {
    if ($size === 'large') {
        $max_image_size = array(800, 600);
    }
    return $max_image_size;
}

Override Maximum Image Size for Thumbnails

Override the maximum image size for thumbnail images.

add_filter('editor_max_image_size', 'override_max_image_size_for_thumbnails', 10, 4);
function override_max_image_size_for_thumbnails($max_image_size, $size, $context) {
    if ($size === 'thumbnail') {
        $max_image_size = array(200, 200);
    }
    return $max_image_size;
}

Remove Image Size Limit for Editor

Remove the maximum image size limit when inserting images into the editor.

add_filter('editor_max_image_size', 'remove_image_size_limit_for_editor', 10, 4);
function remove_image_size_limit_for_editor($max_image_size, $size, $context) {
    if ($context === 'edit') {
        $max_image_size = false;
    }
    return $max_image_size;
}