1

I'm tearing my hair trying to get additional image sizes appear in the media section when i upload new pictures. It works on older versions of wordpress but i can't get it to work on v 3.5.2

Here's my code in the functions.php file and i'm using the underscores.me framework to build the theme.

/*
    Custom image sizes
*/

add_action('after_setup_theme', 'images_setup');

function images_setup() {

    add_theme_support('post-thumbnails');

    if (function_exists('add_image_size')) {
        add_image_size('slider', 1170, 400, true);
    }
    // Getting these sizes to appear in the media section within wordpress
    add_filter('image_size_names_choose', 'my_custom_image_sizes');

    function my_custom_image_sizes($sizes) {
        $custom_sizes = array(
            //'custom-post-thumbnail' => 'Custom Post Thumbnail',
            'slider' => 'Slider'
        );

        return array_merge($sizes, $custom_sizes);
    }

}
4
  • 1
    Have you seen and tried the solutions from this thread?
    – fuxia
    Jun 24, 2013 at 5:42
  • I'll check it out but i certainly don't want to use a plugin to achieve it. Thanks tischo :)
    – arkhamDev
    Jun 24, 2013 at 6:01
  • Tried it out, still not working :)
    – arkhamDev
    Jun 24, 2013 at 6:12
  • With the code in place, try uploading another image, and make sure it's bigger than 1170 x 400. If that solves nothing, we've got a mystery (because I just tried your code in 3.5.2 & it works perfectly!). Jun 24, 2013 at 6:47

1 Answer 1

2

I'm running WordPress 3.5.2. The following is an excerpt from my functions.php file, which correctly allows me to select a thumbnail size when I upload an image.

// Basic setup for thumbnail support.
function themeSetup()
{
    add_theme_support('post-thumbnails');

    add_image_size('tiny', 128, 79);
    add_image_size('small', 256, 158);
    add_image_size('medium', 384, 237);
    add_image_size('large', 512, 316);
}
add_action('after_setup_theme', 'themeSetup');

// Addes custom sizes to Media Library.
function addMySizes($defaultSizes)
{
    $mySizes = array
    (
        'tiny' => 'Tiny',
        'small' => 'Small',
        'medium' => 'Medium',
        'large' => 'Large'
    );  

    return array_merge($defaultSizes, $mySizes);
}  
add_filter('image_size_names_choose', 'addMySizes');

As you'll notice, we have pretty similar answers. I'm not a PHP expert, but those nested functions give me the willies. I would unnest them and see if that fixes your code. Maybe it's just a timing issue, i.e. your call to add_filter() is too early.

If this doesn't fix the problem, then it's probably something else. Try deactivating all your plugins, etc, standard WordPress debug procedure.

1
  • Thank you :) all i did was added the tiny, small, medium and large sizes and moved my add_filter below the function that adds my sizes and it worked.
    – arkhamDev
    Jul 7, 2013 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.