0
votes

I am building a custom theme and trying to customize the sizes list of media library,but did not work for me, i`m using the code in codex

add_image_size( 'custom-size', 220, 180, true ); 
add_filter( 'image_size_names_choose', 'my_custom_sizes' );

function my_custom_sizes( $sizes ) {
  return array_merge( $sizes, array(
     'custom-size' => __( 'Your Custom Size Name' ),
  ) );
}

enter image description here

Note: I`m using Wordpress 4.1 :)

2

2 Answers

0
votes

the image size name doesn't match in your array_merge function

'your-custom-size' => __( 'Your Custom Size Name' ),

should be

'custom-size' => __( 'Your Custom Size Name' ),
0
votes

A lot of time has passed (and I'm on WordPress 4.7), but I was having the same issue tonight and found a solution. Instead of

add_image_size( 'custom-size', 220, 180, true ); 
add_filter( 'image_size_names_choose', 'my_custom_sizes' );

function my_custom_sizes( $sizes ) {
  return array_merge( $sizes, array(
     'custom-size' => __( 'Your Custom Size Name' ),
  ) );
}

I had to refactor my code to pass my function as the second parameter to add_filter, like so:

add_image_size( 'custom-size', 220, 180, true ); 
add_filter( 'image_size_names_choose', function ( $sizes ) {
  return array_merge( $sizes, array(
     'custom-size' => __( 'Your Custom Size Name' ),
  ) );
} );

I came up with this solution after right-clicking the empty 'Size' dropdown on the Media select screen and choosing 'Inspect Element', which allowed me to see the error. I'm not sure if changes in WordPress or my host (Site5) caused the issue, but I hope this answer will help someone.