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(); |
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; |
You can then tailor the logic to anything WordPress allows.
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. 🙂
Glad it helped!
Spencer – super helpful post. I’m struggling to figure out Genesis and this solved a big issue for me. Thx!