2

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.

  • can you confirm that these functions are actually getting called by echoing some text? – Dharmang Dec 26 '14 at 9:03
  • Yes they are getting called perfectly. – iSaumya Dec 26 '14 at 9:49
  • I have another question. You see I've mentioned the width of my custom image size as 740 and hight as per the image. Now when I'm regenerating the thumbnails, its generating 650x488 instead it should generate 740x555 as the full image size is 1024x768. Why this is happening? Screenshot: i.imgur.com/FPJ6dZm.jpg Please help. – iSaumya Dec 26 '14 at 10:02
2

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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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