NO BUG: Image_size_names_choose not being honoured in functions.php

This may be related to this bug, but I believe I have a different issue so wanted to report it.

I am also using the Custom Image Sizes: Cheat Sheet in the Brick Child Theme functions.php. The custom image sizes are correctly registered and the various image sizes generated upon upload. However, within Bricks, or Gutenberg, when selecting the image size dropdown, the human readable name as specified in the add_filter( ‘image_size_names_choose’ …) does not display. Instead, the ‘slug’ name is displayed.

For example, when using the following code, you would expect to see ‘Cropped 1:1 1920px’ listed in the image size dropdown, however when Bricks theme is enabled, the slug name ‘1x1-crop-1920px’ is displayed in the dropdown.

Example function.php code >>

add_image_size( '1x1-crop-1920px', 1920, 1920, true ); // Hard Crop Mode

function wpb_custom_image_sizes( $size_names ) {
    $new_sizes = array(
        '1x1-crop-1920px' => 'Cropped 1:1 1920px'
    );
    return array_merge( $size_names, $new_sizes );
}
add_filter( 'image_size_names_choose', 'wpb_custom_image_sizes' );

Interestingly, if I comment out line 23 in bricks/includes/admin.php

// add_filter( 'image_size_names_choose', [ $this, 'image_size_names_choose' ] );

Then the ‘image_size_names_choose’ filter in functions.php is honoured and the human readable image size names are displayed in the dropdowns.

In summary, it seems to me that admin.php is not allowing the ‘image_size_names_choose’ filter in functions.php (or a code snippet plugin) to function correctly.

Hey Stewart,

thanks for your report.

However, I can’t confirm that. Using the snippet from the thread you provided the image sizes are shown as expected for me:

Best,

André

Strange. Let me do a clean install and try again. Perhaps it is something to do with LocalWP. If I can replicate the issue on a clean install perhaps I can send you the LocalWP install file?

Hey Stewart,

sure. My screenshot is from a LocalWP install as well though. :smiling_face:

Best,

André

Hi André,

Well, I have done a clean install and like you, it works fine. I’m sorry to have wasted your time. I need to go back to my staging site to try and better understand what is going wrong.

Thank you for your time. Much appreciated.

Stewart

Hey Stewart,

no problem. If you have any findings it‘d be great if you could post them here so anyone who stumbles upon a similar issue can maybe find a possible solution in this thread. :smiling_face:

Best,

André

My human readable image size names are not showing up in menus.

I am confused. You and @aslotta indicate that the screenshot posted proves the filter works correctly, but ‘Cropped 1:1 1920px’ is not shown in the screenshot.

Did you resolve this issue? Any suggestions?

Please see: SOLVED: Implement image_size_names_choose hook to change image size label in the builder

1 Like