Skip to content

Instantly share code, notes, and snippets.

@designbuildtest
Created July 30, 2014 23:12
Show Gist options
  • Save designbuildtest/367037e18fbee47f5ccf to your computer and use it in GitHub Desktop.
Save designbuildtest/367037e18fbee47f5ccf to your computer and use it in GitHub Desktop.
Featured Image with captions
if ( ! function_exists( 'mytheme_entry_image' ) ) :
/**
* Display an optional entry thumbnail.
*/
function mytheme_entry_image() {
if ( ! has_post_thumbnail() ) {
return;
}
$featured_image = get_post_thumbnail_id();
$attachment_page = esc_url( get_attachment_link( $featured_image ) );
$caption = get_post(get_post_thumbnail_id())->post_excerpt;
?>
<dl class="entry-image">
<dt class="entry-image-container">
<?php
if ( ! is_singular() ) : ?>
<a href="<?php echo esc_url( get_permalink() ); ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="bookmark">
<?php the_post_thumbnail( 'large' ); ?>
</a><?php
else :
the_post_thumbnail( 'large' );
endif;
?>
<a class="entry-image-more" href="<?php echo $attachment_page; ?>" title="<?php _e('Image details', 'sendtheme'); ?>">
<?php _e('Image details', 'sendtheme'); ?>
</a>
</dt><!-- .entry-image-container -->
<?php
// Show the hand-crafted image caption (if available)
if ( trim( $caption ) ) : ?>
<dd class="entry-image-caption">
<?php echo wptexturize( $caption ); ?>
</dd><!-- .entry-image-caption --><?php
endif;
?>
</dl><!-- .entry-image --><?php
}
endif; // mytheme_entry_image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment