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

Browser: Chrome 124.0.6367.208
OS: Windows

I added a custom image size in the Bricks child theme. Please note the name I set for the image size - ‘1540px Wide Image Scaled’

<?php

#IMAGE SIZES CUSTOMIZED
add_theme_support( 'post_thumbnails' );
add_image_size( 'image-1540', 1540, 9999);

function img_sizes__tap( $sizes )
{
		return array_merge ($sizes, array(
			'image-1540' => __( '1540px Wide Image Scaled' ),
			)
		);
}

add_filter( 'image_size_names_choose', 'img_sizes__tap' );
#/IMAGE SIZES CUSTOMIZED

?>

Below is a screenshot of the Image element’s size control within the Bricks Builder. Please note the highlighted name.
image

I MAY know why the Bricks Builder does not display the name I set. Please note the highlighted code in the screenshot below from a Bricks’ admin file (includes/admin.php).
image

I did not know how to change that function in the child theme, so I changed it in the Bricks parent theme as an experiment on a staging website (see code below). The Image element’s size control did not change. Suggestions?

	/**
	 * Add custom image sizes to WordPress media library in admin area
	 *
	 * Also used to build dropdown of control 'images' for single image element.
	 *
	 * @since 1.0
	 */
	public function image_size_names_choose( $default_sizes ) {
		global $_wp_additional_image_sizes;
		$custom_image_sizes = [];

		foreach ( $_wp_additional_image_sizes as $key => $value ) {
			/*$key_array         = explode( '_', $key );
			$capitalized_array = [];

			foreach ( $key_array as $string ) {
				array_push( $capitalized_array, ucfirst( $string ) );
			}

			$custom_image_sizes[ $key ] = join( ' ', $capitalized_array );*/
			$custom_image_sizes[ $key ] = $value;
		}

		return array_merge( $default_sizes, $custom_image_sizes );
	}

@itchycode,
Adding priority to the filter and restoring the parent theme code did not change the image element’s size control.

add_filter( ‘image_size_names_choose’, ‘img_sizes__tap’, 100 );

Thanks,

Travis

Hi Travis,

Just checked our code.
Currently, we didn’t use this filter hook inside the builder.
The code includes/admin.php not related to the builder.

And that’s the reason your code doesn’t work.
We will enhance it so you can use this hook to change the image size labels in the builder as well.

Regards,
Jenn

1 Like

Hi Travis,

We’ve fixed this issue in Bricks 1.9.9 beta, now available as a manual download in your account (see changelog).

Please let us know if you are still experiencing issues.

As with any beta release, please do not use it on a production/live website. It is only meant for testing in a local or staging environment.

1 Like

I’m running Bricks 1.11. The problem persists.

Was the solution not added to the production release yet?

Hi @Travis

The hook is supported since 1.9.9

Example:

add_filter( 'image_size_names_choose', 'img_sizes__tap' );

function img_sizes__tap( $sizes ) {
  return array_merge( $sizes, [
      'full' => __( 'Jenn Full' ),
  ] );
}

In the builder:

Regards,
Jenn