Custom image size in Media Dropdown

I’ve tried everything you have said, but it’s not working on my site. I’m using the below function:

function setup_image_sizes() {
    if ( function_exists( 'add_image_size' ) ) {
        add_image_size( 'blog_body_img', 740, 0, true );
    }
}
add_action( 'after_setup_theme', 'setup_image_sizes' );*/

function post_image_sizes($sizes){
    $custom_sizes = array(
        'blog_body_img' => 'Blog Body Image'
    );
    return array_merge( $sizes, $custom_sizes );
}
add_filter('image_size_names_choose', 'post_image_sizes');

But in the dropdown it is not coming up. See the screenshot below:
Screenshot

I would have been posted this on the comment, but unfortunately below 50 reputation, I’m not allowed to comment. So, I’m looking forward for any help.

Also as I’m using a child theme, where I’m overwriting some of my parent theme image type. So, I’ve also tried this below code, but still not working.

function img_update() {
    if ( function_exists( 'add_image_size' ) ) {
        add_image_size( 'blog_feat_img', 720 ); //overwriting parent theme
        add_image_size( 'latest_posts_widget_feat_img', 400 ); //overwriting parent theme
        add_image_size( 'portfolio_widget_feat_img_1x', 400 ); //overwriting parent theme
        add_image_size( 'portfolio_widget_feat_img_2x', 800 ); //overwriting parent theme
        add_image_size( 'blog_body_img', 740, 0, true ); //My own size
    }
}
add_action( 'after_setup_theme', 'img_update', 11 );


    function post_image_sizes($sizes){
        $custom_sizes = array(
            'blog_body_img' => 'Blog Body Image'
        );
        return array_merge( $sizes, $custom_sizes );
    }
    add_filter('image_size_names_choose', 'post_image_sizes', 11);

Please help me to fix this, as I have no idea where I’m doing this wrong. I’m placing this functions in my child theme’s function.php. Please help.

Note:
I’m already aware that someone else has posted this kind of question before in this forum and I’ve also checked this thread (How to get custom image sizes into media uploader dropdown?) for reference, but it didn’t fixed my issue. Also as I don’t have 50 repotation, I cant place comment. So I had no other way to open a new thread for this. I’m sorry.

1 Answer
1

The above problem got fixed after regenerating the thumbnails and by using the following function.

function mytheme_image_size_names( $sizes ) {
    $sizes['blog_body_img'] = __( 'Blog Body Image', 'isaumya' );

    return $sizes;
}
add_filter( 'image_size_names_choose', 'mytheme_image_size_names', 11, 1 );

Leave a Comment