I’m writing this post out of necessity. I did numerous Google searches, and read through numerous tutorials, and was severely disappointed with the results.
There are options withing Genesis for displaying featured images on the blog/archive pages, but it doesn’t have any options for displaying featured images on individual posts. My search results only wielded plugins, out-dated tutorials, or blogs behind paywalls – nothing quick, and nothing easy.
So, naturally, I came up with my own solution, and it’s easy as pie. Simply plop the following code in your functions.php file:
function single_featured_image() { if ( is_single() ) { if ( has_post_thumbnail() ) { the_post_thumbnail('large', array('class'=>'alignleft post-image')); } } } add_action( 'genesis_before_entry', 'single_featured_image');
And it will yield something like this:
Explaining the Code
If you’re inquisitive like me, you’re probably asking what exactly does that bit of code do?
- Creates a function.
- Checks whether or not the page is a single post, using
if ( is_single () )
- Checks whether or not the post has a featured image, using
if ( has_post_thumbnail() )
- If you’re on a single post, and it has a featured image, it gets the featured image, in the indicated size, large, and outputs it with the correct classes, alignleft and post-image, using
the_post_thumbnail();
- Tells WordPress to run the function before the post title, using the hook
genesis_before_entry
.
Customizing the Code
While you can plop this code into any Genesis Child Theme and it will work, it may not look the way you want it to. If this is the case, you may want to tweak the snippet in order to match your vision, or current theme.
For instance, say you want the featured image to appearĀ after the post title. To do this, simply go to the Visual Hook Guide, and find the hook you need (in this case, genesis_entry_header
) and adjust the code accordingly:
function single_featured_image() { if ( is_single() ) { if ( has_post_thumbnail() ) { the_post_thumbnail('large', array('class'=>'alignleft post-image')); } } } add_action( 'genesis_entry_header', 'single_featured_image');
And you get this:
You can also change the featured image size, class, and other attributes by editing the arguments for the_post_thumbnail();
, as found in the Codex. By playing with different image attributes, classes, and hooks, you can ensure your featured image is displayed properly on your single posts.
Hopefully, this brief post will save a lot of headaches, frustration, and hours Googling. If you have any questions, feedback, or comments, feel free to leave a comment.
Satria says
Thank you very much for this, been struggling and I thought my Genesis install was broken.
Apparently they didn’t include the featured image in single post, how weird is that >.<
Thanks again Kyrie!
Kyrie Tompkins says
No problem, glad I could help!
jimandthem says
Exactly what I was looking for! Thank you so much for sharing
Kyrie Tompkins says
No problem, glad it helps!
Sandee says
HI, Kyrie!
I just stumbled upon your blog after you posted a link to a PSD to Genesis child theme you were working on in the Facebook group. You are so very talented! This is a great snippet, and you’re right — so much quicker than a lot of solutions I’ve come across.
Thanks and continued luck with your business!
Sandee
Andrew says
Hi Kyrie, thanks so much for these Genesis codes! I also searched feverishly for a code that would put the featured image AFTER the title so thanks for anticipating that need! Keep up the good work.
Best,
Andrew
Elen says
Hi, very nice and usefull.
I have one pending doubt: how to perform the same on pages?
Thank you in advance!
Elena
p.s. nice blog!
Kyrie Tompkins says
To do it on pages, you’d need to tweak the code slightly. Instead of this line:
is_single()
you’d wantis_page()
.The whole code would look like this:
Ibrahim Vatih says
I just add this feature to my genesis, thank you
mushelpi says
but not work properly on my site
Kyrie Tompkins-Overlock says
Hi Mushelpi!
This works on most Genesis child themes, but may not work on every single one of them. You may need to find a different hook (instead of
) or change the priority depending on the child theme you’re using.