如何将自定义图像大小添加到媒体上传程序下拉菜单中?

时间:2013-07-03 作者:B L Praveen

我在网上搜索以解决从媒体上传的图像大小问题。但对我来说,一个都不管用。当我尝试将媒体中的图像插入post时,它不会显示我的自定义图像大小608 X 350 px

function setup_image_sizes() {
    if ( function_exists( \'add_image_size\' ) ) {
        add_image_size( \'post-image\', 608, 350, true );
    }

    function post_image_sizes($sizes){
        $custom_sizes = array(
            \'post-image\' => \'Post Image\'
        );
        return array_merge( $sizes, $custom_sizes );
    }

    add_filter(\'image_size_names_choose\', \'post_image_sizes\');
}

add_action( \'after_setup_theme\', \'setup_image_sizes\' );
请告诉我

1 个回复
最合适的回答,由SO网友:Nicolai Grossherr 整理而成

试着像这样分开:

    function setup_image_sizes() {
        if ( function_exists( \'add_image_size\' ) ) {
            add_image_size( \'post-image\', 608, 350, true );
        }
    }
    add_action( \'after_setup_theme\', \'setup_image_sizes\' );

    function post_image_sizes($sizes){
        $custom_sizes = array(
            \'post-image\' => \'Post Image\'
        );
        return array_merge( $sizes, $custom_sizes );
    }
    add_filter(\'image_size_names_choose\', \'post_image_sizes\');
这样,它在我的设置中工作。

其他来源:custom image size with New Media Manager in wordpress 3.5
-http://ahjira.com/add-custom-image-sizes-to-media-library-size-selection-drop-down-list/

结束

相关推荐

Hover images and Videos

我用这个代码在我的博客上显示视频循环。它工作得很好。作用phpfunction catch_video() { global $post, $posts; $first_vid = \'\'; ob_start(); ob_end_clean(); $output = preg_match_all(\'/<iframe.+src=[\\\'\"]([^\\\'\"]+)[\\\'\"].*>/i\', $post->post_c