Last active
August 16, 2016 08:09
-
-
Save nickdavis/2b07d4e1bc639b4a8c06cc2757458422 to your computer and use it in GitHub Desktop.
Check the width of a post's featured image in WordPress and use it to determine which image size should be displayed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function nd_featured_image_size_sniff() { | |
if ( ! has_post_thumbnail() ) { | |
return; | |
} | |
$featured_image_id = get_post_thumbnail_id( get_the_ID() ); | |
$featured_image_metadata = wp_get_attachment_metadata( $featured_image_id ); | |
if ( $featured_image_metadata['width'] > 819 ) { | |
// Display large image size | |
} else { | |
// Display fallback smaller image size | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment