admin管理员组文章数量:1431398
I have created a new image size using the add_image_size(), and I want to have it listed in the media library image size when I insert it. So I have the following code:
add_image_size( "grade-image", 320, 300, true );
function sgr_display_image_size_names_muploader( $sizes ) {
$new_sizes = array(
"0" => "grade-image",
);
/*
$added_sizes = get_intermediate_image_sizes();
// $added_sizes is an indexed array, therefore need to convert it
// to associative array, using $value for $key and $value
foreach( $added_sizes as $key => $value) {
$new_sizes[$value] = $value;
}
*/
// This preserves the labels in $sizes, and merges the two arrays
$new_sizes = array_merge( $new_sizes, $sizes );
return $new_sizes;
}
add_filter('image_size_names_choose', 'sgr_display_image_size_names_muploader', 11, 1);
however, it does not show the grade-image size. I tried the commented block to show a list of all image sizes, and it does show some of the other image sizes, but not the grade-image one. I'm really puzzled.
I have created a new image size using the add_image_size(), and I want to have it listed in the media library image size when I insert it. So I have the following code:
add_image_size( "grade-image", 320, 300, true );
function sgr_display_image_size_names_muploader( $sizes ) {
$new_sizes = array(
"0" => "grade-image",
);
/*
$added_sizes = get_intermediate_image_sizes();
// $added_sizes is an indexed array, therefore need to convert it
// to associative array, using $value for $key and $value
foreach( $added_sizes as $key => $value) {
$new_sizes[$value] = $value;
}
*/
// This preserves the labels in $sizes, and merges the two arrays
$new_sizes = array_merge( $new_sizes, $sizes );
return $new_sizes;
}
add_filter('image_size_names_choose', 'sgr_display_image_size_names_muploader', 11, 1);
however, it does not show the grade-image size. I tried the commented block to show a list of all image sizes, and it does show some of the other image sizes, but not the grade-image one. I'm really puzzled.
Share Improve this question asked Aug 13, 2013 at 2:12 AngelaAngela 4504 silver badges12 bronze badges3 Answers
Reset to default 7No, that seems to work right. You could test it by doing
<?php echo get_the_post_thumbnail('grade-image'); ?>
try this.
add_image_size( "grade-image", 320, 300, true );
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'grade-image' => __('Grade Image'),
) );
}
David's code will probably work but you should not use the add_image_size() function in that way. Check the example below :
add_action( 'after_setup_theme', 'my_custom_image_sizes' );
function my_custom_image_sizes() {
if ( function_exists( 'add_image_size' ) ) {
add_image_size( "grade-image", 320, 300, true );
}
}
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'grade-image' => __('Grade Image')
) );
}
Make sure you use the hook 'after_setup_theme' to avoid incompatibility errors.
add_image_size( "grade-image", 320, 300, true );
//required parameters 3 and 4
add_filter( 'image_size_names_choose', 'my_custom_sizes', 10, 1 );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'grade-image' => __('Grade Image'),
) );
}
本文标签: media libraryimagesizenameschoose filter doesn39t show
版权声明:本文标题:media library - image_size_names_choose filter doesn't show 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745580653a2664601.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论