如果你想在后台 > 媒体库,直截了当地了解上传的文件大小(占用空间)和尺寸,如下图所示,只要按照本文的方法进行操作即可。

显示占用空间:下载安装 Media File Sizes 插件即可,All Sizes 表示包括缩略图在内所有大小,Original 表示原图大小。
显示尺寸(图片文件):
将下面的代码添加到当前主题的functions.php 即可:
/**
* 在<a href="https://www.wpdaxue.com/tag/%e5%aa%92%e4%bd%93%e5%ba%93" title="查看与【媒体库】相关的文章" target="_blank" rel="noopener">媒体库</a>显示文件尺寸
* From https://www.wpdaxue.com/display-image-size-dimensions.html
*/
add_filter('manage_upload_columns', 'size_column_register');
function size_column_register($columns) {
$columns['dimensions'] = __('Dimensions');
return $columns;
}
add_action('manage_media_custom_column', 'size_column_display', 10, 2);
function size_column_display($column_name, $post_id) {
if( 'dimensions' != $column_name || !wp_attachment_is_image($post_id))
return;
list($url, $width, $height) = wp_get_attachment_image_src($post_id, 'full');
echo esc_html("{$width}×{$height}");
} |
/**
* 在<a href="https://www.wpdaxue.com/tag/%e5%aa%92%e4%bd%93%e5%ba%93" title="查看与【媒体库】相关的文章" target="_blank" rel="noopener">媒体库</a>显示文件尺寸
* From https://www.wpdaxue.com/display-image-size-dimensions.html
*/
add_filter('manage_upload_columns', 'size_column_register');
function size_column_register($columns) {
$columns['dimensions'] = __('Dimensions');
return $columns;
}
add_action('manage_media_custom_column', 'size_column_display', 10, 2);
function size_column_display($column_name, $post_id) {
if( 'dimensions' != $column_name || !wp_attachment_is_image($post_id))
return;
list($url, $width, $height) = wp_get_attachment_image_src($post_id, 'full');
echo esc_html("{$width}×{$height}");
}
如果你想在编辑媒体时,也显示文件大小,如下图:

只需将下面的代码添加到当前主题的 functions.php 即可
/**
* 在媒体编辑页面显示文件大小
* From http://maorchasen.com/blog/2013/01/27/show-file-size-information-on-attachment-screen/
* @author Maor Chasen
*/
function mc_attachment_submitbox_filesize() {
$post = get_post();
$filesize = @filesize( get_attached_file( $post->ID ) );
if ( ! empty( $filesize ) && is_numeric( $filesize ) && $filesize > 0 ) : ?>
<div class="misc-pub-section">
<?php _e( '文件大小:' ); ?> <strong><?php echo size_format( $filesize ); ?></strong>
</div>
<?php
endif;
}
add_action( 'attachment_submitbox_misc_actions', 'mc_attachment_submitbox_filesize' ); |
/**
* 在媒体编辑页面显示文件大小
* From http://maorchasen.com/blog/2013/01/27/show-file-size-information-on-attachment-screen/
* @author Maor Chasen
*/
function mc_attachment_submitbox_filesize() {
$post = get_post();
$filesize = @filesize( get_attached_file( $post->ID ) );
if ( ! empty( $filesize ) && is_numeric( $filesize ) && $filesize > 0 ) : ?>
<div class="misc-pub-section">
<?php _e( '文件大小:' ); ?> <strong><?php echo size_format( $filesize ); ?></strong>
</div>
<?php
endif;
}
add_action( 'attachment_submitbox_misc_actions', 'mc_attachment_submitbox_filesize' );
来源:
https://www.wpdaxue.com/display-image-size-dimensions.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32459.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57