Add size in Gallery Settings in Media Library

I would like to add the size in the Gallery Settings in the Add Media.

I know to add the in the front-end by editing the media.php.

Read More

However, when I added the the lines in gallery.dev.js, they don’t seem to work.

Here are the lines I had added in gallery.dev.js

Added size

 setup : function()
      var t = this, a, ed = t.editor, g, columns,size, link, order, orderby;

Added galsize in the same setup : function (approx line 128)

 if ( getUserSetting('galsize') ) t.I('size').value = getUserSetting('galsize');

Added in setup : function (approx line 141)

 size = a.match(/order='"['"]/i);

Added in setup : function (approx line 150 )

 if ( size && size[1] ) t.I('size').value = size[1];

Added size in update : function (approx line 170)

   all = all.replace(/s*(order|link|columns|size|orderby)=['"]([^'"]+)['"]/gi, '');

Added in getsettings : function

    if ( I('size').value != 'medium' ) {
            s += ' size="'+I('size').value+'"';
            setUserSetting('galsize', I('size').value);
        }

Related posts

Leave a Reply

1 comment

  1. first +1 for the first commenter .
    NEVER CHANGE CORE FILES.

    this function will do the trick for your media upload :

    function dl_custom_image_sizes_add_settings($sizes) {
           unset( $sizes['thumbnail']); //comment to remove size if needed
           //unset( $sizes['medium']);// uncomment to remove size if needed
           //unset( $sizes['large']);// uncomment to restore size if needed
           unset( $sizes['full'] ); // comment to remove size if needed
           $mynewimgsizes = array(
                  "your-custom-size_name-1" => __( "Name_to_display1" ),
                  "your-custom-size_name-2" => __( "Name_to_display2" ),
                  "your-custom-size_name-3" => __( "Name_to_display3" )
           );
           $newimgsizes = array_merge($sizes, $mynewimgsizes);
           return $newimgsizes;
    }
    add_filter('image_size_names_choose', 'dl_custom_image_sizes_add_settings');
    

    of course , this will work only if you define them first like so :

    /*
    Post Thumbnails Support
    */
    add_theme_support( 'post-thumbnails', array( 'post' ) ); // Add it for posts
    add_image_size( 'your-custom-size_name-1', 220, 100, true ); // Permalink thumbnail size
    add_image_size( 'your-custom-size_name-2', 50, 50, true ); // example home  thumbnail size
    add_image_size( 'your-custom-size_name-3', 470, 350, false ); //  slider size
    

    otherwise it will show greyed out buttons..