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:
- Display random categories on the front page (Finding and Editing Theme Functions)
- Automatically set the featured image
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- 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?
- Linking thumbnail to full size image
- Generating Responsive Background Image Sizes in PHP
- 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
- Make WordPress size and name images for Retina.js
- How to add a rel attribute to images that contains their categories?
- 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?
- Delete Post From Front-End and attachment permanently
- 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
- How would go about if I just want a temporary function?
- Remove the deleted users avatar from list
- How to call custom function from functions.php in site-wide template files?
- Customizer field value into functions.php variable
- How to display a default image for post thumbnail using functions.php?
- Change size and crop medium_large images
- str_replace function in theme
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- Right way to update widget on dynamic new input field
- How to customly read JWPlayer’s “Playlist” items by using its “playlistid”?
- set_post_thumbnail when user is not logged in
- Twentyten Child Theme: header images display messed up in admin panel
- IF Statement on Button to make it complete and “uncomplete” based on user action / click
- Gravity Forms Button Text
- Can you put a condition on add_image_size() depending on the width of the uploaded image?
- Find resources dynamically loading and change or add to the url
- When sale price is 0.00 show only regular price
- Word Press – Dynamic Content [closed]
- Insert image in WordPress with HTML5 tag and caption function
- how can I just add to parent theme function(s) instead of redeclaring whole the function
- Can’t generate thumbnail images
- Move Custom Fields on General Settings Page to New Location
- Skeleton Child Theme Add Icon Bar to Header Flex Grid
- Redirect to another page using contact form 7? [closed]
- Check if the image size is available and if not use ‘full’ image size
- Custom Behavior when Adding New Custom Post Type in Dashboard
- Why There Is No “get content by ID” Function
- Custom HTML markup
- How to hide image-url if no attachment?
- Use a shortcode to display custom meta box contents
- Create custom function for hero image
- Can set_post_thumbnail be used to remove a thumbnail?
- Randomizing wp_tag_cloud() in child theme
- How to append classname to body tag if guest user
- Where do I go to edit this area? [closed]
- Replace plugin function with a custom function?
- How to add a new image size and apply it to posts only?
- Function to replace comment’s accented characters before posting
- New checkbox in custom widget isn’t saving data
- Linking Javascript in functions.php file
- resizing of thumbnails not working
- Featured Image keeps cropping
- struggling with syntax for the_post_thumbnail();
- include w_thumbnail_src in function?
- How to replace ACTION url from original wordpress login form?
- Modifying a WordPress Plugin
- Hide author info in single posts by certain users
- External api call and make global variable for any page visitor enters , page-home, page, single etc
- CSS style and app.js not loading
- Can You Set A Minimum Image Dimension For Resizing Images?
- Parent category as WOOCommerce Categories widget title
- I want to customize the_posts_navigation function by replacing prev and next with images
- How would I correctly implement a new if statement in a child functions file?
- Featured image on archive page based on post type
- True email confirmation for registration (keeping unvalidated users from user table)
- How To Show Shortcodes In WordPress Custom Fields?
- Best way to add image to recent posts widget?
- How to make an If Else on Excerpt Filter
- custom post with loading script per single post
- Apply height and width for the_content() inside youtube video tag
- Get Value of Custom Field
- restrict access to specific urls on a specific period of time
- child_of not working while searching
- How to request login for user but not for bots
- Removing Facebook contact field from user contact not working
- How do I add functionality to images?
- Is mytheme_post_thumbnails() still necessary?
- Problem with removing characters “<” – WpAllImport
- How to create a post without link in wordpress?
- multible shortcodes (for differnt values) with one function
- Customizer cuistom CSS Priority ordre Issue