I want to add a new image size option to the contents image editor. The code below is what I currently have but for some reason I am not seeing the option (as shown in the image below) in the editor. I am using WordPress Version 4.6.1. What could be the problem? Thanks in advance.

enter image description here

    add_image_size( 'activity-image', 300, 300, array( 'center', 'center' ) );

    // Add new image sizes to post or page editor
    function new_image_sizes($sizes) {
        return array_merge( $sizes, array(
            'activity-image' => __( 'Activity Image' ),
        ) );
    }
    add_filter('image_size_names_chooser', 'new_image_sizes');

3 Answers
3

You need to register the image size first using add_image_size(), for example:

add_action( 'after_setup_theme', 'cyb_add_image_sizes' );
function cyb_add_image_sizes() {
    add_image_size( 'my-image-size-name', 120, 120, true );
}

Then, you can use the image_size_names_choose filter (you have misspelled it with image_size_names_chooser):

add_filter( 'image_size_names_choose', 'rudr_new_image_sizes' );
function rudr_new_image_sizes( $sizes ) {

    $addsizes = array(
        "my-image-size-name" => 'Misha size'
    );

    $newsizes = array_merge( $sizes, $addsizes );

    return $newsizes;

}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *