Last active
February 20, 2017 09:29
-
-
Save srikat/fa25a25364d75a4c57fe to your computer and use it in GitHub Desktop.
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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' ) ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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