Skip to content

Instantly share code, notes, and snippets.

@Ikaring
Last active December 26, 2015 09:39
Show Gist options
  • Save Ikaring/7131421 to your computer and use it in GitHub Desktop.
Save Ikaring/7131421 to your computer and use it in GitHub Desktop.
WordPress shortcode for retrieving (pdf or any) file size.
<?php
// [filesize file="filename.pdf"]
function get_file_size($atts) {
extract(shortcode_atts(array(
'file' => '',
), $atts));
//pdfの置き場所にあわせてパスを設定
$mfile=WP_CONTENT_DIR."/pdf/".$file;
if ( is_file($mfile) ){
$filesize = size_format( filesize($mfile) );
} else {
$filesize="ファイルがみつかりません";
}
return $filesize;
}
add_shortcode('filesize', 'get_file_size');
?>
@Ikaring
Copy link
Author

Ikaring commented Jan 22, 2015

I've made a plugin for this purpose.
https://wordpress.org/plugins/get-filesize-shortcode/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment