Skip Navigation

[Resolved] How to add Custom Sizes to the Image Blocks of Toolset → Field Settings → Image Size?

This thread is resolved. Here is a description of the problem and solution.

Problem:
We are using Custom Sizes registered in our Theme and would like to use them when inserting Single Image Blocks with Dynamic Source in Toolset

How to do this?

Solution:
You'll not only need to register your custom Image Size but also add support for it's GUI Image Size picker.

It is exampled here step by step how to proceed:
https://toolset.com/forums/topic/dynamic-image-source-in-a-loop-item-no-longer-shows-custom-image-sizes/#post-1600293

This support ticket is created 4 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.15 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 5 replies, has 2 voices.

Last updated by lindsayH 4 years, 6 months ago.

Assisted by: Beda.

Author
Posts
#1598273
firefox_2020-04-23_22-27-10.png

I have two image sizes and certainly until recently I used to be able to simply select these in the Image Settings > Image Size.

Now I only see the standard WordPress sizes (Thumbnail, Medium, Large) and Full Size.

I used to be able to select my Custom Sizes below?

 add_image_size( 'blog', '800', '400', true );
add_image_size( 'portfolio', '570', '390', true );

See image (I used the Edit Custom Size to create the 'Resized to: 800 x 400 px option in the Image Size list)

Is this a change or a bug?

#1599019

Right, the Custom Image Sizes added with add_image_size() are not used, you can, however, add custom sizes directly in the Inspector

I tested with older versions and this never seems to have been working properly
I've escalated the problem to the developers for a closer look

#1600293

I'm sorry, it was my mistake.

Please let me show you how to add custom sizes so that they appear in both WordPress and Toolset (Blocks) Image size settings.

1. You should register the custom image sizes like so in the theme's functions.php:

add_image_size( 'first', '100', '120', true );
add_image_size( 'second', '300', '120', true );
//etc

2. Then, you should register the options to show in the GUIs, using your custom sizes:

add_filter( 'image_size_names_choose', 'the_custom_sizes_as_registered_by_you' );
 
function the_custom_sizes_as_registered_by_you( $sizes ) {
    return array_merge( $sizes, array(
        'first' => __( 'First' ),
        'second' => __( 'Second' )
    ) );
}

3. Then, you need to upload an image that is bigger than your defined sizes

4. Now you will be able to insert such an image in a Toolset Image Field, and using the Dynamic Image Blocks Inspector Settings you can then select your custom sizes.

PS:
- If the image is smaller, or the sizes are not registered to hook "image_size_names_choose", it won't work. You can read more here about the WordPress hook image_size_names_choose: https://developer.wordpress.org/reference/hooks/image_size_names_choose/
- Make sure to load your in add_image_size() after_setup_theme hook: https://developer.wordpress.org/reference/hooks/after_setup_theme/

#1600315

I will have a go at adding the filter in point 2.

The add_image_size was already in my child theme's functions.php and was previously all that was required to show up in the GUI. Only after very recent updates have they disappeared from the list. Elsewhere in the WordPress GUI I can see them listed, e.g. Genesis Featured Posts widget.

#1600335

This is an old requirement in WordPress

As we tested it never was different, also in the WordPress media uploader. It's just new in the Blocks because the blocks are new and before we did not interact with the image_size_names_choose filter as there was no need for it (it was all shortcodes options).

In any case, it would be the expected form of implementation, because also the WP Media Uploader will require this, as the Second Tier also confirmed on the issue.

Please let me know if it works for you as well.

#1600831

My issue is resolved now. Thank you!

Adding the code outlined in step 2 to my child theme's functions.php resolved the issue.