Skip to content

Instantly share code, notes, and snippets.

@katlove
Last active January 16, 2016 14:54
Show Gist options
  • Select an option

  • Save katlove/fa0fff9b601bc813c63d to your computer and use it in GitHub Desktop.

Select an option

Save katlove/fa0fff9b601bc813c63d to your computer and use it in GitHub Desktop.
<?php
// Add home hero image as a background in head of home template only w/ media query
// Make sure you have a <div class="home-hero-image"> on the front page template
if( function_exists('get_field') ) {
if ( ! function_exists( 'home_hero_image' ) ) :
add_action( 'wp_head', 'home_hero_image', 16 );
function home_hero_image()
{
if ( 'is_front_page' And (get_field('home_hero_image'))) {
echo
"<style>
@media (min-width: 500px) {
.home-hero-image {
background-image: url('";
the_field('home_hero_image');
echo "');}
}
<!--[if lte IE 8]>
.home-hero-image { background-image: url('";
the_field('home_hero_image');
echo "'); }
<![endif]-->
</style>";
}
}
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment