Skip to content

Instantly share code, notes, and snippets.

@topleague
Created August 24, 2019 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topleague/72f605d62ac19ba6cd18d130b5c63bdf to your computer and use it in GitHub Desktop.
Save topleague/72f605d62ac19ba6cd18d130b5c63bdf to your computer and use it in GitHub Desktop.
Overlay Entry Title/Post Info/Meta on Featured Image on Single Post
// Register a custom image size for hero images on single Posts
add_image_size( 'post-image', 1600, 400, true );
add_action( 'genesis_before_entry', 'sk_hero_image' );
function sk_hero_image() {
// if we are not on a single Post, abort.
if ( !is_singular( 'post' ) ) {
return;
}
// set $image to URL of featured image. If featured image is not present, set it to post-image.jpg in child theme's images directory.
if ( has_post_thumbnail() ) {
$image = genesis_get_image( 'format=url&size=post-image' );
} else {
$image = get_stylesheet_directory_uri() . '/images/post-image.jpg';
} ?>
<div class="post-hero" style="background-image:linear-gradient(rgba(0,0,0, 0.4), rgba(0,0,0, 0.4)), url('<?php echo $image; ?>')">
<div class="wrap">
<?php genesis_post_meta(); ?>
<?php genesis_post_info(); ?>
<?php genesis_do_post_title(); ?>
<?php echo do_shortcode('[post_author_posts_link]'); ?>
<?php echo do_shortcode('[postview]'); ?>
<?php echo do_shortcode('[post_comments zero="0" one="1" more="% Comments"]'); ?>
</div>
</div>
<?php
// Remove entry title
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment