Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Last active April 16, 2019 14:06
Show Gist options
  • Save leepettijohn/6f51b9ab443296369329 to your computer and use it in GitHub Desktop.
Save leepettijohn/6f51b9ab443296369329 to your computer and use it in GitHub Desktop.
Add image to top of pages and posts
add_image_size( 'featured-top', 750, 500, TRUE );
add_action ('genesis_before_loop','add_top_image');
function add_top_image(){
if (is_page() || is_single()){
the_post_thumbnail('featured-top',array('class'=>'top-of-post'));
}
}
// Use this one if it's full width and needs to be a background image
add_action('genesis_after_header','add_top_img',12);
function add_top_img(){
if (is_page()){
echo '<div class="top-image" style="background-image:url(';
the_post_thumbnail_url();
echo ')"></div>';
}
}
.top-image {
width: 100%;
height: 255px;
background-size: cover;
background-position: center;
}
@media screen and (max-width:1023px){
/* This includes 768px*/
.top-image {
height: 200px;
}
}
@leepettijohn
Copy link
Author

change 750 and 500 to correct dimensions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment