Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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();
- if ( wp_is_mobile() ) {
- // insert featured image after the first paragraph
- $content = preg_replace( '/<\/p>/', '</p>' . get_the_post_thumbnail( $post->ID, 'post-single' ), $content, 1 );
- } else {
- // 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 );
- }
- if ( wp_is_mobile() ) {
- return $content . $sidebar;
- } else {
- return $content;
- }
- }
- genesis();
Add Comment
Please, Sign In to add comment