Skip to content

Instantly share code, notes, and snippets.

@brycejacobson
Created December 26, 2013 19:59
Show Gist options
  • Save brycejacobson/8138008 to your computer and use it in GitHub Desktop.
Save brycejacobson/8138008 to your computer and use it in GitHub Desktop.
Add featured image to Genesis single post with full control of options. Also a cleaner version with no image link.
<?php
// Add featured image to single posts.
add_action ( 'genesis_entry_content', 'aafcm_show_featured_image_single', 1 );
function aafcm_show_featured_image_single() {
global $post;
if ( is_page() )
return; // Make pages act normal
//setup thumbnail image args to be used with genesis_get_image();
$size = 'thumbnail'; // Change this to whatever add_image_size you want
$default_attr = array(
'class' => "alignright attachment-$size $size",
'alt' => $post->post_title,
'title' => $post->post_title,
);
// This is the most important part! Checks to see if the post has a Post Thumbnail assigned to it. You can delete the if conditional if you want and assume that there will always be a thumbnail
if ( has_post_thumbnail() && is_single() ) {
printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), genesis_get_image( array( 'size' => $size, 'attr' => $default_attr ) ) );
}
}
<?php
// Add featured image to single posts.
// Cleaner approach. No image link.
add_action ( 'genesis_entry_content', 'aafcm_show_featured_image_single', 1 );
function aafcm_show_featured_image_single() {
if ( has_post_thumbnail() && is_single() ) {
$img = genesis_get_image( array( 'size' => 'thumbnail', 'attr' => array( 'class' => "alignright" ) ) );
printf( '%s', $img );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment