Use wp_get_attachment_metadata()
.
Using your example:
$img_data = wp_get_attachment_metadata( $attachment_id );
$w = $img_data['width'];
$h = $img_data['height'];
if ($w > $h) {
$class = "col-sm-12";
} else {
$class = "col-sm-6";
}
Though, to get the attachment ID, you’ll either have to put a filter that acts on every image or create a loop that uses featured images.
Related Posts:
- Removing height and width from images with a caption
- How to implement CSS-defined images from bootstrap site in wordpress theme
- Using a full-width hero image that can be changed in the dashboard by a user
- Responsive images in Bootstrap 4 slider
- get attachment title based on attachment id
- get_post_gallery_images returns thumbs . I want full size
- Media Upload Folder – how to manage
- Wrong image dimensions in Insert Media after add_image_size()
- PHP Fatal error: Call to undefined function download_url()
- Remove P tags from images
- Any easy way to automatically set the first inline image in a post as the thumbnail?
- Upload multiple images in a custom metabox
- How can I hide media library images from general users?
- WordPress speed slow after .5 million single image post via wp-cli
- How to add php to theme to show alt attributes
- Why won’t these imported images show up?
- Remove rel=”attachment wp-att-XX”
- Using Taxonomy Image code with my get_categories code
- Generate image size, based on the image-orientation
- Rename image during upload using date and time stamp?
- How to Add extra option to Image Block Settings?
- Upload thousands of images to WordPress without plugin?
- Images in the Twenty Fourteen theme
- Get author ID with attachment ID
- Show Post Excerpt in Image Attachement
- Automatically replace original uploaded image with large image size
- Problem with loading images from child theme CSS file with relevant path
- wp_get_attachment_url with specific image_size?
- Bulk edit Gutenberg single images to change from linking to media file to attachment page
- is it possible to crop cover images in buddypress?
- Any specific reason why images do not show on site?
- Disallow img tag in comments?
- Bulk edit of EXIF data for jpeg images uploaded in the media library?
- In Wordress one author can not see the other’s author uploaded images through media library
- How to add missing dimensions to all images to avoid cls?
- Why are images created by WP larger than the original uploaded image?
- Scaling images for mobile
- How do I fix “Sorry, this file type is not permitted for security reasons”
- Replace image caption with its title and description
- Image LazyLoad plugin not loading jQuery dependancies with wp_enqueue_script in WP 3.3.1
- How to make thumbnails of uploaded animated gifs NOT animated
- Frontend Image Upload
- Multiple variables through wp_get_image_editor
- Removing featured image from gallery?
- Rewrite inline image markup
- Function to remove all classes on images inserted into posts?
- Images don’t update after being edited
- URL through custom field returning null
- How to set a Background image in WordPress?
- Weird encoded error when using wp_generate_attachment_metadata()
- big trouble with javascript
- Local install not loading template images but is loading everything else XAMPP
- Display cropped thumbnail not featured image
- Hide image gallery in Woocommerce if NO image [closed]
- All 3?: Responsive resizing of images + image width of actual image for small images + max-width for all larger images
- How to get the cropped image from media library?
- wordpress makes duplicate images of different size
- Attachments without images
- Responsive Images from S3 has no srcset
- Image modification
- How to only show div of caption if caption exists on featured image
- How to “lazy load” post thumbnail
- Using srcsets in a custom block
- Landing Page with HTML CSS JS and Images on wordpress
- Change Image URL on upload to some random number automatically
- wp_insert_attachment() dupplicate attachment posts
- Image title replace with current date
- WordPress Responsive Image ( srcset ) not work properly
- Product Gallery Images to go into full size on Product Page
- How to Display Image Caption but Not Alt Text
- Why image Thumbnail url is not displaying with custom size?
- Why does wp_get_attachment_image_src return the wrong size, when the correct size exists?
- add_image_size limiting sizes (???)
- WooCommerce Variation Swatches and Photos – get attribute thumbnail
- Automatically generate multiple image sizes for element
- link image file path embedded HTML
- Responsive Images in WordPress
- Is it possible to remove spaces from existing images? [closed]
- get_post_meta returning broken path in image src
- Custom WordPress Theme – No Slider(s) Images
- Get image from one page and show/add it on another page
- Featured image on page set as “Posts page” in Settings > Reading
- problem with updating metabox of upload image
- How to have a specific image show up for everyone who comments?
- Adding Image Description below Images Inserted into Posts
- Using file extensions in image titles
- Garbled HTML pulled for page description “caption id=attachment…”
- Media upload in add comment meta box
- Create post thumbnails from images stored outside of uploads directory
- php.ini -Theme-specific settings
- How do I set the sizes of my thumbnails when inserting a [gallery]?
- Display X images from a gallery in the sidebar
- Automatically adding blog images to a portfolio/gallery
- How do I insert a photo at the top of the sidebar?
- How to get attached image alt text in media.php?
- Why some images are not allowed to be edited only for thumbnails?
- problems with alt text not appearing in source code
- I am having trouble displaying an image at the top of a widget area [closed]
- How to disable Right Click on a image? [closed]
- Can’t upload svg files in WordPress