Home / functions.php / Add custom image sizes to media insert dialog box with image_size_names_choose
  • How to Add custom image sizes to media insert dialog box with image_size_names_choose

    custom-image-sizes-media-insert-dialog-box-image_size_names_choose

    With this little snippet you can add custom image sizes to media insert dialog box. image_size_names_choose allows modification of the image size lists so that you can place a custom option within the media library.

    ( Example: screenshot ) ( click code to copy )

    wordpress snippet : PHP

    <>
    if ( function_exists( 'add_image_size' ) ) {
        add_image_size( 'new-size', 300, 100, true ); //(cropped)
    }
    add_filter('image_size_names_choose', 'my_image_sizes');
    function my_image_sizes($sizes) {
            $addsizes = array(
                    "new-size" => __( "New Size")
                    );
            $newsizes = array_merge($sizes, $addsizes);
            return $newsizes;
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

    image_size_names_choose, add_filter, add_image_size, __, _n, _e, _ex, wp,