Last active
March 8, 2018 21:34
-
-
Save cccamuseme/7d913a2e91538d6aeec172e9371f1dd6 to your computer and use it in GitHub Desktop.
WordPress featured image as background with fallback image
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
<?php | |
//define fallback image path | |
$thumb = get_template_directory_uri().'/images/fallback-image.jpg'; | |
if ( has_post_thumbnail() ) { | |
//override fallback image if post has any thumbnail | |
$thumb = get_the_post_thumbnail_url(); | |
} | |
?> | |
<div class="page-header" style="background-image: url('<?php echo $thumb;?>')"> | |
<h1><?php the_title(); ?></h1> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment