Have a look to wp_get_attachment_image_src(), which gives precisely data you need (URL and dimensions). Which help to figure out your problem.
sample code
$image_attributes = wp_get_attachment_image_src( $attachment_id = 10 );
if ( $image_attributes ) : ?>
<img src="https://wordpress.stackexchange.com/questions/302831/<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>" />
<?php endif; ?>
The return section gives keys, but the function just returns indexes as.
array{
[0] => url,
[1] => width,
[2] => height,
[3] => is_intermediate (boolean)
}
We should make it clearer what is returned by this function. And some description or a link to explain is_intermediate.
Related Posts:
- Missing feature image link function
- Add multiple custom fields to the general settings page
- When should you, and when should you not, use wp_list_pluck()?
- Display random categories on the front page (Finding and Editing Theme Functions)
- Is it possible to remove the “standard” post format?
- Woocommerce add to simple product attribute programmatically [closed]
- Issue with get_theme_mod returning a blank value instead of the saved value
- How to remove row-actions from pages table?
- Automatically set the featured image
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- Get recent posts with thumbnail
- Modify search function in WordPress (TwentyTwelve)
- How to display the_post_thumbnail if a post has one or otherwise display the first image in a post?
- How to customize search result page title?
- Add options to featured image
- Auto delete WordPress images/thumbnails (all sizes) and featured after X days/hours, or similar?
- Linking thumbnail to full size image
- Generating Responsive Background Image Sizes in PHP
- How to fix a theme with page.php Default Template that accidentally deleted?
- Why are image thumbnails cropped proportionally (not per dimensions)?
- Removing Unnecessary Text from Admin Menu without CSS
- Set default options for inserting media
- Default or Preset Content for Custom Post Types
- Add a Post Thumbnail to an RSS Feed with custom size
- Remove tag on my RSS Feed
- Display WordPress Search
- How do I change parameters without changing the core
- Problem with extract() with custom shortcode
- Make WordPress size and name images for Retina.js
- How to add a rel attribute to images that contains their categories?
- add sidebar area to header of child theme
- Why are image thumbnails cropped proportionally (not per dimensions)?
- Preferred Use of home_url()?
- the_post_thumbnail fallback using hooks
- Display height and width properties with the_post_thumbnail() or related function
- Custom function for user register in wp?
- Setting featured image with function, 1 part not working
- Delete Post From Front-End and attachment permanently
- Theme-Config tab in admin Pannel?
- Creating loop within functions.php
- How to Add a Random Custom Gravatar in the WordPress Comments?
- Removing the first image in content
- How to set the jpg image compression for specific thumbnail sizes?
- Function to auto-set a featured image that is already in use
- Delete pages and Create default pages for all new network sites
- Actions according to image type and size
- Post thumbnail relative link and HTML modify
- Refactor create_function
- adding custom classes for tables
- Pass Shortcode Attribute to footer Script
- How to mass-delete inline styles in WordPress custom post type automatically?
- How would go about if I just want a temporary function?
- Remove the deleted users avatar from list
- img width and height attributes being set by get_the_post_thumbnail
- How to call custom function from functions.php in site-wide template files?
- Customizer field value into functions.php variable
- PHP files included in functions.php don’t seem to work
- Get the 5 lastest Featured Posts from a category
- How to display a default image for post thumbnail using functions.php?
- How Can I Expand the WordPress Customize window without any Plugin?
- Change size and crop medium_large images
- Set quantity of woocommerce product on page visit [closed]
- wp_dropdown_categories and custom attribute
- str_replace function in theme
- Getting Featured Image Caption to Only Show if Populated
- wp_get_attachment_image function size argument not working if I also add a custom class
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Add Featured image column into wordpress admin on pages AND posts
- Automatically wrap multiple images in div
- Ajax not working properly
- Post thumbnail not showing in WP admin area for custom post type
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- Overwriting Parent Theme’s Image Sizes
- Backstretch.js and thumbnail sizes to reduce loading time
- Right way to update widget on dynamic new input field
- Why does modifying my functions.php file always result in a server error
- Post variables not displaying correctly in custom function
- Remove snippets of JS from core
- Image width issue in IE [closed]
- Removing Facebook contact field from user contact not working
- How do I add functionality to images?
- Explode Array from Repeatable Custom Field
- image_size with respect to aspect ratios
- Is mytheme_post_thumbnails() still necessary?
- WordPress Custom wp mail template return full template
- Problem with removing characters “<” – WpAllImport
- How to create a post without link in wordpress?
- How to crop image in WordPress with aspect ratio for any size of image
- multible shortcodes (for differnt values) with one function
- post_row_actions filter from parent theme not executing in child theme
- Customizer cuistom CSS Priority ordre Issue
- Copy and Modified WooCommerce function is_coupon_valid [closed]
- BuddyPress Edit activity function good practice
- wp_login_form display no styled form
- Advanced Custom Fields in WP_Query: Clickable Text in List Format
- Second featured image only shows in metabox preview after saving a post in the wordpress editor
- Add custom css to specific user
- How can I restrict comments on WordPress, so only the POST AUTHOR and the user who commented can see them?
- No src and sizes attributes present on WordPress thumbnail images; the smallest image size is loaded irregardless of viewport size
- add_image_size() parameter four ($crop = true) is ignored: the_post_thumbnail() returns scaled image(s) instead of hard cropped