Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Wordpress image size not showing in 3.5 Media Manager

I have a theme which uses add_image_size to define several custom image sizes. These 5 image sizes used to show up in the Wordpress 3.4 media manager when inserting an image into a post but they no longer show up in the new Wordpress 3.5 Media Manager. In fact, the only image size options i get when I try to "Add Media" to a post are Thumbnail (100x100) and Full Size (3260x988). Obviously my theme settings are not overriding the default media settings in Settings >> Media. Here is the code from my functions.php file:

function custom_theme_support() {
  add_theme_support('post-thumbnails');
  set_post_thumbnail_size(180, 120, true);
  add_image_size( 'hero-desktop-2x', 3200, 800, true);
  add_image_size( 'hero-desktop', 1600, 400, true);
  add_image_size( 'hero-mobile-2x', 1534, 800, true);
  add_image_size( 'hero-mobile', 767, 400, true);
}

add_action('after_setup_theme','custom_theme_support');

So, my question is what do i need to do to make my theme override the Wordpress Admin settings in Wordpress 3.5?

like image 501
kirley Avatar asked Jan 06 '13 05:01

kirley


2 Answers

I've used the following code, which seems to work.

Note: you must regenerate all your thumbnail for this size to appear retroactively on already existing images:

function setup_image_sizes() {
    if( function_exists('add_theme_support') ) {
        add_theme_support('post-thumbnails');
    }
    if ( function_exists( 'add_image_size' ) ) {
        add_image_size( 'custom-image', 576, 320, true );
    }

    function my_image_sizes($sizes){
        $custom_sizes = array(
            'custom-image' => 'Custom Image'
        );
        return array_merge( $sizes, $custom_sizes );
    }

    add_filter('image_size_names_choose', 'my_image_sizes');
}

add_action( 'after_setup_theme', 'setup_image_sizes' );
like image 59
makbeta Avatar answered Nov 05 '22 13:11

makbeta


When I had similar problems in the past I had to add the images with the image_size_names_choose filter. That was pre-WordPress 3.5 though; you say it was working on 3.4, so I don't know if it'll help, but it's worth a try.

There's an example in step two of this tutorial.

like image 41
Hobo Avatar answered Nov 05 '22 13:11

Hobo