Skip to content

Instantly share code, notes, and snippets.

@raaar
Created June 12, 2013 10:31
Show Gist options
  • Save raaar/5764269 to your computer and use it in GitHub Desktop.
Save raaar/5764269 to your computer and use it in GitHub Desktop.
Display thumbnail if present, or alternative content
<?php if (has_post_thumbnail( $post->ID ))
{
$image_url = wp_get_attachment_image_src(get_post_thumbnail_id(),'large', true);
echo '<div class="news-thumb" style="background-image: url(' . $image_url[0] . ')"></div>';
}
else
{
echo '<div class="news-thumb" style="background-image: url('. get_bloginfo('template_directory') .'/images/logo-footer.png)"></div>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment