Created
August 1, 2013 16:58
-
-
Save jeffsebring/6133212 to your computer and use it in GitHub Desktop.
thumbnail size fallback
This file contains 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
/** | |
* Print Selected Thumbnail Images | |
* @return string|bool thumbnail html or false | |
*/ | |
function pU01_thumbnail_img( $size = 'secondary_image', $attr = array() ) { | |
// Fallback to featured image | |
if ( ! $thumbnail_id = get_post_meta( get_the_ID(), get_post_type() . "_{$size}_thumbnail_id", true ) ) { | |
if ( ! $thumbnail_id = get_post_meta( get_the_ID(), "_thumbnail_id", true ) ) | |
return false; | |
} | |
// Return with thumbnail filter for lazy loading | |
return apply_filters( 'post_thumbnail_html', wp_get_attachment_image( $thumbnail_id, $size, false, $attr ), get_the_ID(), $thumbnail_id, $size, $attr ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment