Basic check of aspect ratio. Display as landscape, square or portrait
if ( !has_post_thumbnail()) {
return 'Error';
} else {
$image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '');
$image_w = $image[1];
$image_h = $image[2];
if ($image_w > $image_h) {
echo 'landscape';
}
elseif ($image_w == $image_h) {
echo 'square';
}
else {
echo 'portrait';
}
}
Related Posts:
- Find posts without featured image? [duplicate]
- How to get relative URL of medium sized featured image?
- How to set the width and height rule for featured image
- Gutenberg editor get post featured image by id
- Big Image on Featured Post, Normal on Single Post
- How to use photo in multiple posts?
- Setup Featured image on all posts from thesis thesis_post_image custom field?
- How do I link a featured photo to it’s post?
- Title image is missing ( but is not the WP 3.5 issue )
- How to show file size of featured image? [duplicate]
- How to show file type of featured image?
- How to change image type for specific size?
- What’s the proper way to find and remove duplicate images from posts and the media library?
- get_post_gallery with Gutenberg
- Mixed content warnings after changing site adress from HTTP to HTTPS
- add_image_size() zoom-crop
- Insert an image into a post by API
- Creating a rotating header /image slider using theme customization
- Add aditional class to get_avatar when showing image
- Use Media Library to manage galleries like Nextgen (with folders, albums, collections, tags, categories, terms…)
- Double thumbnails?
- No srcset for hard-cropped thumbnails
- Slider image issue in wordpress
- Getting custom size image URL
- Retrieving images from a NextGEN gallery
- Query for recent images across multiple posts
- Getting alt text of featured image
- Get image alt attribute just by image URL
- Is there a way to get attachment data?
- How to resolve – IE 6 ignores img “width” properties
- WordPress is stripping the Alt tag’s quote marks from images where Alt is not set, but leaving the word ‘alt’ creating problems for ADA compliance
- WordPress reduces the full size image and uses it as the original
- Show taxonomy list with taxonomy images ( SOLVED)
- get_children() not working properly – Only on one post?
- Warning: getimagesize() [function.getimagesize]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 [closed]
- Is There A Way Of Using the_post_thumbnail() to Pull In A Specific Image From The Media Library
- How to add data attribute to all images in posts [closed]
- How to order images in a post in WordPress 3.3?
- Output random (custom) image size
- WordPress crops images differently on retina screens?
- Image thumbnails not available post migration, but still accessible via direct URL – DB issue
- Override img class in gallery
- How do I create an alternate RSS feed for tags with custom image sizes for MailChimp?
- Exclude images from “inserted into post” when trying to get attachments
- Set jpeg_quality for certain post-types
- WordPress automatically downscaled images larger that original
- Move Image Captions Inside Link ( tag) if Added
- Sharing images to social media – issue with aspect ratio
- How to add custom classes to figure element only if image has caption?
- I got an issue after i migrated a site
- How to add an image to a custom url?
- I want to use the GD image editor for just one function then switch back to ImageMagick
- 409 error (Conflict) when trying to insert an image into a post
- Exclude image titles from search results
- Facebook og:image issues after https change [closed]
- Does WP create multiple images?
- Thumbnails generated by “add_image_size” are not removed when removing media
- How to use Facebox in WordPress theme?
- Mass crop images: Landscape images -> Portrait images
- Change image name during uploading sequentially
- Store in media library image uploaded from url
- How to redirect homepage to actual URL?
- Get images attached to a specific page
- add_image_size function not working
- Stop WordPress compressing images? – Quality is terrible
- Cropped image file size larger than original, is it normal?
- How to make Custom Loop not crop featured images?
- Using mysql to replace img src?
- wordpress add image size crop function not working in version 3.8
- How do I display the featured image from an image gallery using a reference in code? (example within)
- caption shortcode inserts blank paragraph
- Doing a bulk replace of images through back-end
- How to change background slider image when hovering on text?
- Can I achieve this with WordPress?
- Built-in image lazy loading: Does it come with a polyfill for older browsers?
- SQL: How to find all attachments that are not used in any posts/pages/custom_post_types
- I would like to set a FULL SCREEN background image to all my pages (same way it is on my home page)
- Enlarge Featured WordPress Images
- WordPress 4.4.2 upload give error, can’t write is upper directory allowed to be written
- How to add element to the list of adjacent images?
- Responsive Images – Defining
- How to attach 1000’s of unattached images
- WordPress Javascript displaying an image Question
- Using a full-width hero image that can be changed in the dashboard by a user
- Resize External Image
- Images are not getting uploaded
- Unable to delete images in Media Library
- Background image call problem
- Assigning image to Post-Type won’t work anymore: exceeded time?
- How to specify image width and/or height attributes for images uploaded using WordPress uploader
- How to change default image rename?
- Link images to post
- Image attachement management – a philosophical question
- wp_get_attachment_link() add rel attribute if the link points to direct image
- Getting top Image From the Gallery and printing out a thumbnail with Exact Dimensions
- Add custom version to an image
- How to get some information from the_content [closed]
- Custom Background Image per Page
- Delete all thumbnails & regenerate them?
- Gutenberg block HTML image rendering override