• Hi, guys! I bought a template with its single post’s featured image doesn’t show the caption. How can I modify my wp template to show caption under the featured image within a single post view? The template developer wouldn’t willing to modify this. Please help me!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Hi @janurmas, We unfortunately can’t help you with this because we don’t support commercial themes. It sounds like you might have to hire someone: https://jobs.wordpress.net

    generally, to show captions under the featured image in the single post, try to add this code to functions.php of your (child) theme:

    
    // dec 17 2016 @alchymyth
    // filter for single post, in the loop, to show caption, if available, on thumbnail, wrapped with '.wp-caption thumb-caption' div;
    // show just the thumbnail otherwise
    
    add_filter( 'post_thumbnail_html', 'add_post_thumbnail_caption',10,5 );
    
    function add_post_thumbnail_caption($html, $post_id, $post_thumbnail_id, $size, $attr) {
    
    if( $html == '' || !is_single() || !in_the_loop() ) { //do this only for single post in the loop//
     
    	return $html;
     
    } else {
     
    	$out = '';
     
    	$thumbnail_image = get_posts(array('p' => $post_thumbnail_id, 'post_type' => 'attachment'));
     
    	if ($thumbnail_image && isset($thumbnail_image[0])) {
     
    		$image = wp_get_attachment_image_src($post_thumbnail_id, $size);
    
    		if($thumbnail_image[0]->post_excerpt) 
    			$out .= '<div class="wp-caption thumb-caption">';
     
    		$out .= $html;
     
    		if($thumbnail_image[0]->post_excerpt) 
    			$out .= '<p class="wp-caption-text thumb-caption-text">'.$thumbnail_image[0]->post_excerpt.'</p></div>';
      
    	}
    
    	return $out;
      
    }
    }

    might need to be adapted to work with your commercial theme.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘My Template doesn’t support caption under the featured image’ is closed to new replies.