Support » Plugins » image_size_names_choose not working

  • Topher

    (@topher1kenobe)


    I’m trying to get the Image Uploader to show my cutom image sizes in the list. Here’s my code:

    function custom_wmu_image_sizes($sizes) {
            $myimgsizes = array(
                    "vnn-slide-cropped" => __( "VNN Slide" )
                    );
            $newimgsizes = array_merge($sizes, $myimgsizes);
    
            return $newimgsizes;
    }
    add_filter('image_size_names_choose', 'custom_wmu_image_sizes');

    When I do a print_r on $newimgsizes I can see that me new sizes are actually in there, but they don’t render on the page, which makes me think my filter isn’t working properly. I don’t know how to debug that though. 🙁

    Where do I go from here?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Topher

    (@topher1kenobe)

    I figured it out. I had previously altered $sizes in another function that ran AFTER this one, killing my changes. All set now.

    Dude, does this code put your custom images sizes into the standard WordPress upload/insert dialog?? That rocks. So the code snippet above is good as long as I can create the array of my sizes, and obviously VNN is your prefix…?

    Thread Starter Topher

    (@topher1kenobe)

    Yep, that’s exactly what it does.

    Than

    foreach( $added_sizes as $key => $value) {
    		$new_sizes[$value] = $value;
    	}

    Here’s my version, which grabs all the custom defined sizes and formats them prettily:

    add_filter( 'image_size_names_choose', 'ml_custom_image_choose' );
    function ml_custom_image_choose( $args ) {
    
    	global $_wp_additional_image_sizes;
    
    	// make the names human friendly by removing dashes and capitalising
    	foreach( $_wp_additional_image_sizes as $key => $value ) {
    		$custom[ $key ] = ucwords( str_replace( '-', ' ', $key ) );
    	}
    
    	return array_merge( $args, $custom );
    }

    Good tip, @memelab! I googled that $_wp_additional_images_sizes var as I hadn’t seen it before and found an article recommending the use of get_intermediate_image_sizes() instead (http://www.deluxeblogtips.com/2011/06/list-registered-image-sizes.html). Good stuff!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘image_size_names_choose not working’ is closed to new replies.