Tag Info

Hot answers tagged

3

You can use get_attached_file() to: Retrieve attached file path based on attachment ID. And get_post_thumbnail_id() to determine the post thumbnail of the current post, or any post if you set the $post_id parameter. Exemplary usage: $bytes = filesize( get_attached_file( get_post_thumbnail_id() ) ); Use size_format() to ...


3

Second pass. Known issues: Needs caching (and the cache needs to be tidied up where possible) Post types are hard-coded Which post statuses are we interested in? Here's the function: /** * Given an attachment ID, searches for any post with that attachment used * as a featured image, or if it is present in the content of the post. * (Note above known ...


1

Just as an addition, as an improvement to account for different image sizes, I would do: $file_name = pathinfo( $file, PATHINFO_FILENAME ); $file_extension = '.' . pathinfo( $file, PATHINFO_EXTENSION ); Instead having a combined value for $file. And change the SQL preparation to: $prepared_sql = $wpdb->prepare( $sql, $id, ...


1

You could do like this: function image_tag_class($class) { $class .= ' my-custom-class'; return $class; } add_filter('get_image_tag_class', 'image_tag_class' ); in case you wanna know more about actions and hooks. Difference Between Filter and Action Hooks? add_filter add_action



Only top voted, non community-wiki answers of a minimum length are eligible