• How To?
  • Tips ‘n Tricks
  • WordPress
  • Snippets
  • Software
    • Browsers
    • Downloads
  • Web
  • Tools
    • Character Counter
    • chmod Calculator
    • Entities Encoder
    • Live HTML Editor
    • My IP
  • Contact
Twitter Facebook Google+ RSS
You are here: SumTips » Blogging » Add, Disable & Use Custom Image Sizes in WordPress 3.3 Media Uploader

Add, Disable & Use Custom Image Sizes in WordPress 3.3 Media Uploader

Posted on December 16, 2011 by Renji | Short URL: http://sumtips.com/?p=6087

Quick and easy way to add, disable and use only those image sizes you want in the WordPress Media Uploader.

Images Sizes in WordPress Media Uploader

All codes go inside your active theme’s functions.php file.

Add Custom Image Sizes in WordPress

add_image_size('magazine-thumb', 120, 120, true); //crop
add_image_size('slideshow-thumb', 250, 220, false);
add_image_size('sidebar-thumb', 85, 85, true); //crop

Access Custom Image Sizes in WordPress Media Uploader

To use these newly added image sizes in Media Uploader, we are going to use image_size_names_choose filter introduced in WordPress 3.3

function custom_wmu_image_sizes($sizes) {
        $myimgsizes = array(
                "magazine-thumb" => __( "Magazine" ),
                "slideshow-thumb" => __( "Slideshow" ),
                "sidebar-thumb" => __( "Sidebar" )
                );
        $newimgsizes = array_merge($sizes, $myimgsizes);
        return $newimgsizes;
}
add_filter('image_size_names_choose', 'custom_wmu_image_sizes');

Disable Unwanted Image Sizes in WordPress Media Uploader

Now that you have added your custom image sizes, you can choose to disable creation of thumbnails for default sizes with the following code. If your theme adds any image size, you can disable  that as well similarly.

function remove_wmp_image_sizes( $sizes) {
        unset( $sizes['thumbnail']);
        unset( $sizes['medium']);
        unset( $sizes['large']);

        return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'remove_wmp_image_sizes');

Update: The above function did disable creation of default image sizes, but their radio buttons were still visible in the Media Uploader. To remove those radio buttons as well,  you can use this single function instead of the earlier two:

function custom_wmu_image_sizes($sizes) {
       unset( $sizes['thumbnail']);
       unset( $sizes['medium']);
       unset( $sizes['large']);
       unset( $sizes['full'] ); // removes full size if needed

       $myimgsizes = array(
              "magazine-thumb" => __( "Magazine" ),
              "slideshow-thumb" => __( "Slideshow" ),
              "sidebar-thumb" => __( "Sidebar" )
       );
       $newimgsizes = array_merge($sizes, $myimgsizes);
       return $newimgsizes;
}
add_filter('image_size_names_choose', 'custom_wmu_image_sizes');

Thanks Sébastien.


Tweet

Related posts:

  • Rename Original Filenames of Uploaded Images and Videos on WordPress
  • Customize WordPress TinyMCE Editor With Custom Buttons
  • Add, Delete and Edit Custom Fields in WordPress
  • Upload Images to Multiple Image Hosting Services
  • Customize WordPress HTML Editor With Custom Quicktag Buttons
Categories: Blogging | Tags: WordPress
Set Different Post Templates Based on ID, Tag and Category in WordPress
Add Custom Header Banner Image to Plugin Page on WordPress.org

8 Responses to “Add, Disable & Use Custom Image Sizes in WordPress 3.3 Media Uploader”

  1. Sébastien Méric says:
    December 22, 2011 at 11:06 PM

    hi,

    thanx for the tips :)

    playing a bit with your code, i found that if you are using remove_wmp_image_sizes function then you probably also want to remove the radio buttons that should allow the unwanted types to be selected…

    if so, you may do like this :

    function custom_wmu_image_sizes($sizes) {
    unset( $sizes['thumbnail'] );
    unset( $sizes['medium'] );
    unset( $sizes['large'] );
    unset( $sizes['full'] ); // removes full size if needed

    $myimgsizes = array(
    "magazine-thumb" => __( "Magazine" ),
    "slideshow-thumb" => __( "Slideshow" ),
    "sidebar-thumb" => __( "Sidebar" )
    );
    $newimgsizes = array_merge($sizes, $myimgsizes);
    return $newimgsizes;
    }

    seb.

    • Renji says:
      December 25, 2011 at 10:10 PM

      Thanks for the tip Sébastien. I have updated the post with your method. :)

    • Reitze says:
      December 28, 2011 at 8:35 PM

      Thans Sébastien & Renji, i tried it with the code above.
      But i cannot get the new image sizes to work.

      My code is at this moment:


      add_image_size('magazine-thumb', 120, 120, true); //crop
      add_image_size('slideshow-thumb', 250, 220, false);
      add_image_size('sidebar-thumb', 85, 85, true); //crop

      function custom_wmu_image_sizes($sizes) {
      unset( $sizes['thumbnail']);
      unset( $sizes['medium']);
      unset( $sizes['large']);
      unset( $sizes['full'] ); // removes full size if needed
      $myimgsizes = array( );
      $newimgsizes = array_merge($sizes, $myimgsizes);
      return $newimgsizes;
      }
      add_filter('image_size_names_choose', 'custom_wmu_image_sizes');

      It removes the empty (not used types) but do you know what the bug is? =)

      • Sébastien Méric says:
        December 28, 2011 at 9:23 PM

        hi,

        well, as you remove the 4 default image sizes with unset and don’t give a new list (your $myimgsizes array is empty !) then all radio buttons must have disappeared :)

        you must fill the $myimgsizes array with your new sizes (as in Renji exemple) :
        $myimgsizes = array(
        "magazine-thumb" => __( "Magazine" ),
        "slideshow-thumb" => __( "Slideshow" ),
        "sidebar-thumb" => __( "Sidebar" )
        );

        seb

  2. Derrick says:
    January 30, 2012 at 4:57 AM

    I added this to the functions.php file, but nothing happened. It still shows the original options. Do I need to restart anything? I’m on iPage hosting, so I believe I can’t restart the server

  3. Thomas Scholz says:
    January 30, 2012 at 10:36 PM

    Your code examples are close to invisible.

  4. kas says:
    February 17, 2012 at 1:35 AM

    I want to remove the full size image and want to upload medium size image
    I tried
    unset( $sizes['full'] );

    but its not working for me, full size image radio button is still there

  5. Maxoud says:
    June 14, 2012 at 5:01 PM

    Great stuff! Thank you!

    There is one moment: if you’ve unset all built-in sizes including full-size, you have to return $myimgsizes instead of merging arrays. So the last lines in the function should be:

    if( !empty($sizes) )
        return array_merge($sizes, $myimgsizes);
    else
        return $myimgsizes;
    
  • Get Updates via Email

  • Recent Posts

    • CMS2CMS: Migrate Site from Drupal or Joomla to WordPress
    • WordPress: Add Preview Button in Distraction Free Writing
    • How to Activate or Deactivate Individual Jetpack Modules
    • Windows 8: Auto Update Defender with Windows Update Disabled
    • Automatically Start and Close Programs at Specific Time
    • How to Copy Code from Notepad++ with Syntax Highlighting
  • Random Posts

    • Create a ‘|’ bar Separated Horizontal Menu with CSS3
    • Embed Google’s Pac Man Game on Your Website
    • Create Panoramic Images Online with Dermandar
    • Google Demo Slam
    • Know How to Say a Phrase or Word Correctly with Phras.in
    • Yahoo's YSlow Extension Now Available for Google Chrome
  • Categories

    • Blogging
    • Games
    • Google
    • How To?
    • Linux
    • Microsoft
      • Windows
    • Miscellaneous
    • Phone
    • Snippets
      • AutoHotkey Snippets
      • CSS Snippets
      • htaccess Snippets
      • JavaScript Snippets
      • PowerShell Snippets
      • WordPress Snippets
    • Social
    • Software
      • Browsers
    • Tips 'n Tricks
    • Wallpapers
    • Web
© SumTips. Contact | Sitemap | Privacy Policy