Skip to content

Instantly share code, notes, and snippets.

@jeffsebring
Created August 1, 2013 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffsebring/6133212 to your computer and use it in GitHub Desktop.
Save jeffsebring/6133212 to your computer and use it in GitHub Desktop.
thumbnail size fallback
/**
* 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