Bits & Babble

A blog in development.

Show Featured Image in Genesis Framework

November 21, 2013  

In the past year or so of WordPress development that I’ve done, most of it has been using the Genesis Framework. It’s a great tool I’ve added to my arsenal for starting a new WordPress site. There are a few things, however, it doesn’t do right out of the box. One of those is showing the featured image in a post.

Show Featured Image in Genesis

First, let’s start by pointing out that this code snippet can be injected into your theme in a few different places. I’m going to assume the easiest way is just adding to (or creating) a single.php file in your theme. This file is “used to render a single post page“, so we are narrowing down it’s focus to just posts. Here is a sample single.php file that will display your featured image for a post.

Please note: this sample is for a Genesis 2.0 theme that is using the new HTML5 markup.

1
2
3
4
5
6
7
8
9
10
11
12
<?php
 
/** Hook into the Genesis 2.0 HTML5 action **/
add_action( 'genesis_before_entry_content', 'my_theme_before_entry_content' );
 
function my_theme_before_entry_content() {
 
  if ( has_post_thumbnail() )
    the_post_thumbnail( 'full', array( 'class' => 'alignleft attachment-full' ) );
}
 
genesis();

<?php /** Hook into the Genesis 2.0 HTML5 action **/ add_action( 'genesis_before_entry_content', 'my_theme_before_entry_content' ); function my_theme_before_entry_content() { if ( has_post_thumbnail() ) the_post_thumbnail( 'full', array( 'class' => 'alignleft attachment-full' ) ); } genesis();

There’s not much to is concetpually; we’re just hooking into the proper Genesis action and displaying the thumbnail if there is one. There are a couple of options you can pass to the_post_thumbnail, so go and take a look at the documentation. Here, I’ve just set it up to show the full image and align it to the left of the content area.

If you decide to use this action in your functions.php, but still want the thumbnail to only show for posts, you’ll need to add some logic to your custom function. Like so:

7
8
  if ( ! is_singular( 'post' ) )
    return;

if ( ! is_singular( 'post' ) ) return;

You can then tailor the logic to anything WordPress allows.

3 Comments

By SPENCER SOKOL
  • About
  • Twitter
  • Studio 27

Categories

  • Alloy
  • Android
  • Appcelerator Titanium
  • Babble
  • Debugging
  • Genesis
  • iOS
  • s2Member
  • Woocommerce
  • Wordpress

About Spencer Sokol

Spencer co-founded Studio 27, a small web and application design and development company in Indianapolis. He has spent many years in both the development and testing side of the software industry, and generally avoids talking to people face to face.

Comments

  1. Patty says

    May 28, 2014 at 1:59 pm

    Thank you so much for sharing this – exactly what I needed. Really appreciate you taking the time to make life easier for another Genesis user in the trenches. 🙂

    Reply
    • Spencer Sokol says

      May 28, 2014 at 9:38 pm

      Glad it helped!

      Reply
  2. Jim Dougherty says

    September 6, 2014 at 11:07 am

    Spencer – super helpful post. I’m struggling to figure out Genesis and this solved a big issue for me. Thx!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • About
  • Indianapolis Design & Development
Copyright © 2021 Spencer Sokol

Copyright © 2021 · Bits and Babble on Genesis Framework · WordPress · Log in