如果你想在后台 > 媒体库,直截了当地了解上传的文件大小(占用空间)和尺寸,如下图所示,只要按照本文的方法进行操作即可。
显示占用空间:下载安装 Media File Sizes 插件即可,All Sizes 表示包括缩略图在内所有大小,Original 表示原图大小。
显示尺寸(图片文件):
将下面的代码添加到当前主题的functions.php 即可:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/** * 在媒体库显示文件尺寸 * 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}"); } |
/**
* 在媒体库显示文件尺寸
* 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 即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/** * 在媒体编辑页面显示文件大小 * 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’ );
RSS