Skip to content

Instantly share code, notes, and snippets.

@JanHoek
Created May 18, 2014 15:44
Show Gist options
  • Save JanHoek/997002ed9b86a08a3244 to your computer and use it in GitHub Desktop.
Save JanHoek/997002ed9b86a08a3244 to your computer and use it in GitHub Desktop.
Create a Widget Area with Featured image as background for Genesis
<?php // remove this line
// Register OnTop Widget
genesis_register_sidebar( array(
'id' => 'ontop',
'name' => __( 'OnTop', 'jan' ),
'description' => __( 'This the Ontop widget', 'jan' ),
) );
// Adding option to use featured image (if it exists)
// as background image
add_image_size( 'featured-banner', 2000, 500, TRUE ); // creates a featured image size for the banner
function jan_featured_img() {
if ( has_post_thumbnail() ) { // checks post has thumbnail
// gets URL for that image
$background = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'featured-banner' );
if (is_array($background)) {
// echo the output
echo '<div class="features" style="background: url(' ;
echo $background[0];
echo ') no-repeat scroll center center #FFFFFF"><div class="wrap">';
genesis_widget_area( 'ontop', array(
'before' => '<div class="features-widgetarea">',
'after' => '</div>',
) );
echo '</div></div>';
}}
else { // if no featured image, adds class to use default image
echo '<div class="features"><div class="wrap">';
genesis_widget_area( 'ontop', array(
'before' => '<div class="features-widgetarea">',
'after' => '</div>',
) );
echo '</div></div>';
}}
add_action( 'genesis_after_header', 'jan_featured_img' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment