Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active Feb 20, 2017
Embed
What would you like to do?
How to change featured image location conditionally in Genesis based on Page's layout. https://sridharkatakam.com/how-to-change-featured-image-location-conditionally-in-genesis-based-on-pages-layout/
// Register custom image size for featured image on static Pages
add_image_size( 'static-page', 1200, 250, true );
// Call the function to display featured image depending on which layout is in use on static Pages
add_action( 'genesis_after_header', 'sk_conditional_featured_image' );
function sk_conditional_featured_image() {
// if we are not on a static Page, abort.
if ( ! is_singular( 'page' ) ) {
return;
}
// get the page layout
$site_layout = genesis_site_layout();
// if the page uses sidebar-content-sidebar layout, show featured image above sidebar-content-sidebar.
if ( 'sidebar-content-sidebar' == $site_layout ) {
add_action( 'genesis_before_content_sidebar_wrap', 'sk_featured_image' );
}
// if the page uses content-sidebar layout, show featured image above content.
if ( 'content-sidebar' == $site_layout ) {
add_action( 'genesis_before_entry', 'sk_featured_image' );
}
}
// Function to display featured image
function sk_featured_image() {
genesis_image( array( 'size' => 'static-page' ) );
}
.attachment-static-page {
margin-bottom: 40px;
vertical-align: top;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment