Adding Featured Image in Genesis

I recently switched my site over to Genesis and the Sixteen Nine theme. While I am super impressed with the framework and the child theme, I was disappointed to see that featured images are not included on individual posts.

Because Genesis has such a great community, after a quick search I found an article which described how to add the featured images to individual posts.

Here is that snippet:

[code lang=text]
add_action( 'genesis_after_post_title', 'child_featured_post_image' );
function child_featured_post_image() {
if ( $image = genesis_get_image( 'format=url&size=post-image' ) ) {
printf( '<a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a>', get_permalink(), $image, the_title_attribute( 'echo=0' ) );
}
}
[/code]

But, Natalie’s snippet didn’t work for me…

Featured Image in Genesis HTML5

After a little bit of digging, I found that her code had been written for Genesis 1.x. This was also brought up in the comments, which, in hindsight, I probably should have read before even trying to use the snippet 🙂

Looking at the Genesis Hook Reference, I found the correct hook to use. I then recoded Valerie’s snippet to retrieve the featured image using the_post_thumbnail() , which is a core WordPress function. This is due more to my inexperience with Genesis than anything else. I can’t speak to which method is better.

add_action( 'genesis_before_entry_content', 'child_featured_post_image' );
function child_featured_post_image() {
if( is_single() )
the_post_thumbnail('post-image', array('class'=&gt;'aligncenter'));
}

This snippet will add a featured image to each post, if it exists, and apply a class of aligncenter  to it. You can change the alignment to be left or right aligned simply by changing aligncenter to alignleft or alignright .

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Eric Binnion

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Eric Binnion

Subscribe now to keep reading and get access to the full archive.

Continue reading