Created
December 26, 2013 19:59
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) ) ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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