Reply To: Caption for post thumbnails

Home Forums Support Caption for post thumbnails Reply To: Caption for post thumbnails

Home Forums Support Caption for post thumbnails Reply To: Caption for post thumbnails

#87719
Tom
Lead Developer
Lead Developer

Fair enough, another option is to use a plugin like this: https://wordpress.org/plugins/featured-image-caption/

Then remove the post image function:

add_action('after_setup_theme','generate_remove_post_image');
function generate_remove_post_image()
{
      remove_action( 'generate_after_entry_header', 'generate_post_image' );
}

Then re-add your new function with the caption code:

add_action( 'generate_after_entry_header', 'generate_post_image_caption' );
function generate_post_image_caption()
{
		
	// If there's no featured image, return
	if ( ! has_post_thumbnail() )
		return;
		
	// If we're not on any single post/page or the 404 template, we must be showing excerpts
	if ( ! is_singular() && ! is_404() ) {
	?>
		<div class="post-image">
			<a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_post_thumbnail( 'full', array('itemprop' => 'image') ); ?><?php if ( function_exists( 'cc_featured_image_caption' ) ) : cc_featured_image_caption(); endif; ?></a>
		</div>
	<?php
	}
}