Homepage › Community Forums › Epik Theme Support › How to show Specified Featured Image Only and not Post Images › Reply To: How to show Specified Featured Image Only and not Post Images
LOL, that’s a skeleton of what should work that I posted on the Studio Press forums earlier this week 馃檪
I can explain, and yes, this is a Genesis problem that’s been around since WordPress went to the Featured Image option in, what was it, version 2.9, I think.
If you set a specific Featured Image using the meta box in a new post, that’s your Featured Image, as expected. But if you do not set a Featured Image, Genesis will by default choose the first post image, and use it as a Featured Image, with no way for anyone to override it in any setting, without coming up with a specific filter or function to alter that behavior.
To be clear, this is behavior seen when viewing category/content archives. If viewing the actual post, you won’t see the featured image, but if you view, say, the category News, articles that you didn’t set a featured image for will display the first post image as a featured image if you have the Genesis settings set to “Show Featured Image” in the content archives settings.
I pasted that snippet in the thread francky started over at the Studio Press forums, while still looking for the particular snippet I’d seen before that came close, and I hadn’t found it yet. What I did find this morning is something close, but it won’t work as-is for what he (and a lot of other people) want in terms of functionality.
I found this snippet at Greg Rickaby’s site: http://gregrickaby.com/genesis-code-snippets/
/** Add custom post image above post title */
add_action( 'genesis_before_post_content', 'generate_post_image', 5 );
function generate_post_image() {
if ( is_page() || ! genesis_get_option( 'content_archive_thumbnail' ) )
return;
if ( $image = genesis_get_image( array( 'format' => 'url', 'size' => genesis_get_option( 'image_size' ) ) ) ) {
printf( '<a href="%s" rel="bookmark"><img class="post-image" src="%s" alt="%s" /></a>', get_permalink(), $image, the_title_attribute( 'echo=0' ) );
}
}
<!--formatted-->
It looks like it should be easy enough to modify it to only display a set Featured Image, and not display anything if one isn’t specifically set… I just haven’t had time to play with it to get it tweaked properly.