As far as I know, WordPress has nothing built in for this, I would just do. Same thing did you also. So make sure that the $attachment_id
having value.
You can use custom function by place that function code in your function.php
file.
function getSize($file){
$bytes = filesize($file);
$s = array('b', 'Kb', 'Mb', 'Gb');
$e = floor(log($bytes)/log(1024));
return sprintf('%.2f '.$s[$e], ($bytes/pow(1024, floor($e))));
}
After place above function code, you can use getSize($url);
where ever you use into your template. Here $url
is reference of your file path.
Let me know if this stuff not help you.
Related Posts:
- Add validation and error handling when saving custom fields?
- Max length of meta_value
- The “_encloseme” Meta-Key Conundrum
- Filter WP_Query for posts having a certain meta-value
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- Save HTML formatted data to post meta using add_post_meta()
- Plugin to auto convert custom fields to tag
- Create ul list in Custom Meta Box?
- Order by Custom Field date not recognized
- Display custom field only if value present?
- Advice needed for importing custom field data and database structure
- How to save multiple metaboxes?
- Displaying additional User Contact Information
- get_post_meta in sitewide tags plugin fails to return value for custom fields
- meta_value_num sort glitch
- Populate Custom Field Dropdown on Theme Install?
- WooCommerce conditional required checkout fields [closed]
- Make URL in custom field hyper link
- meta query not showing any results?
- meta_query for a string inside a meta field containing a comma-separated list
- Way To Store Global Meta Values
- Combine multiple custom field values into single value
- Creating a custom menu/widget area
- Can’t get post ID using wp_insert_post_data
- query usermeta from custom field
- Creating author profiles with extra fields and exporting that data?
- Modifying custom order item meta from admin order view
- Let users track progress by entering a number daily in profile?
- WooCommerce – Adding Custom Fields To Invoice
- Changing themes… and need to move Custom Field content into another field
- Filter Posts on Custom Fields and Show them on a new Page
- Removing link ” from ” on meta_value in custom feilds
- How to add a custom field in the advanced menu properties?
- $form_fields from attachment_fields_to_edit returning empty array
- How to link keywords in custom fields?
- Meta query with multiple custom fields for archives page ordering problem
- filter custom field values $min $max
- Customizing WP user profile with custom fields
- Adding custom field to post object from custom table
- Auto embeding Vimeo/Youtube in custom fields (tinyMCE editor)
- How do I use “if field exists” with $curauth?
- Using abs() with custom field in orderby statement
- Can’t save custom field on registration page
- Read more to open external link
- Custom metabox not displaying multiselect data in edit mode
- How to validate select field in post meta?
- How do I query the title (or handle?) of post meta fieldset (created with Simple Fields Plugin)
- Is it preferable to use custom code to create metaboxes instead of plugins (such as ACF) and if so why? [closed]
- Function that replaces the image in the absence of the post meta
- check for duplicate user meta data before updating
- WP Cli – post add meta in xargs after wp post generate – add multiple fields
- Anyone know how to use ACF and show custom fields for logged in users only on a post? [closed]
- How to redirect to home page according to a specific page custom fields value and user name
- How to use pre_get_posts to alter posts_per_page of category pages, where ‘posts_per_page’ will be dynamic
- How to print the Custom fields values [closed]
- How to validation for sanitize_URL?
- ACF Plugin How to make the customer add more fields in the post?
- custom field in admin columns
- Custom metabox not working
- Populate wordpress menu with link to custom field value (file download)
- Selectively hiding or allowing thumbnails of featured images on front page
- wp_get_attachment_image_src() with advanced custom fields returning empty
- Users uploaded image and matching an id or taxonomy
- Adding data to User profile
- How can I change author of posts to the value of one of the custom field of the posts?
- Woocommerce products search with custom fields
- Is it possible to add Term Meta Fields to a WooCommerce Attribute?
- Saving Custom Field that includes Quotation marks
- how to execute custom field for structured data?
- Post meta data not showing in frontend, until hitting ‘update’ button
- Saving custom form data
- register_form, custom field not submitted on first try
- How to properly get popular Posts by multiple Values
- Automatically set the_post_thumbnail to Custom Field Value
- Redirecting to an external URL
- Search one custom field?
- Can’t save meta field value if the title not set
- Why is wp_list_pages altering $post->ID of the page?
- Adding custom fields to images
- How to save dynamically generated value in post type?
- how to show this part only in the single post page?
- How to keep sharing stats after creating 301 redirects?
- Display meta data from a custom field within plugin Category Grid View Gallery
- Checking if field is set before comparing with meta_query in query_posts?
- Calling a custom profile field only it it exists
- Insert wp gallery shortcode into custom textarea
- Display posts where date field matches current month?
- Only show content slideshow if “slideshow” custom field exists
- If post custom meta data is not set, show normal state
- Sort posts after filtering them through multiple taxonomies
- Add values of post meta fields?
- How to include custom field in shortcode (do_shortcode) in theme file
- Query posts by Custom Meta (checkbox) & Genesis Grid Loop
- custom field with links
- Custom fields: Split data from single custom field’s sub-array to separate custom fields when saving post
- How can I copy value from dropdown once I select it to text area as text?
- Create taxonomy terms from custom field values
- Save Custom Meta Value on Media Upload
- How to add new Metadata options (Date, Author, etc.) for Posts?
- Saving multiple custom meta box fields