Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active January 19, 2016 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srikat/8e6cd8562b0bd8f28557 to your computer and use it in GitHub Desktop.
Save srikat/8e6cd8562b0bd8f28557 to your computer and use it in GitHub Desktop.
Entry header, first paragraph, featured Image above the remaining content and sidebar on single Posts in Genesis - Method 1. https://sridharkatakam.com/entry-header-first-paragraph-featured-image-above-the-remaining-content-and-sidebar-on-single-posts-in-genesis/
// Register a custom image size for featured images on single Posts
add_image_size( 'post-single', 1080, 270, true );
<?php
// Add "has-featured-image" body class if the post has a featured image
add_filter( 'body_class', 'sk_single_post_body_class' );
/**
* Adds a css class to the body element
*
* @param array $classes the current body classes
* @return array $classes modified classes
*/
function sk_single_post_body_class( $classes ) {
if ( has_post_thumbnail() ) {
$classes[] = 'has-featured-image';
}
return $classes;
}
add_action( 'get_header', 'sk_layout' );
function sk_layout() {
// if the post does not have a featured image, abort.
if ( ! has_post_thumbnail() ) {
return;
}
// force full width content
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
// insert featured image and Primary sidebar
add_filter( 'the_content', sk_featured_image_sidebar, 20 );
}
// Function to insert featured image and Primary sidebar
function sk_featured_image_sidebar( $content ) {
// store the Primary sidebar's output in a variable using output buffering
ob_start();
get_sidebar(); // include the sidebar.php template file
$sidebar = ob_get_clean();
// insert featured image and Primary sidebar after the first paragraph
$content = preg_replace( '/<\/p>/', '</p>' . get_the_post_thumbnail( $post->ID, 'post-single' ) . $sidebar, $content, 1 );
return $content;
}
genesis();
.attachment-post-single {
margin-bottom: 22px;
}
.single-post.has-featured-image .sidebar-primary {
margin-left: 30px;
}
.single-post.has-featured-image .sidebar .widget {
padding-top: 0;
padding-bottom: 0;
}
.entry-content .sidebar ul {
margin-left: 0;
}
.entry-content .sidebar ul > li {
list-style-type: none;
list-style-image: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment