Featured image caption

NapitWPTech Theme Support Forums The NewsMag Featured image caption

This topic contains 1 reply, has 2 voices, and was last updated by  Bishal Napit 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #229

    Danielle
    Participant

    Using the standard post style, is there a way to display the featured image caption underneath the photo? I am aware that image displays it on the photo but I prefer the captions under the photo as some are lengthy.

    #230

    Bishal Napit
    Keymaster

    Hi Danielle,

    Displaying the image caption in standard post format requires code customization work, which if you can code it on your own then, you can do so via the child theme. You can find the tutorial on child theme as well as the sample child theme from here: https://napitwptech.com/tutorial/wordpress-development/tutorial-creating-wordpress-child-theme/. Now, you can duplicate the file template-parts/content.php in your child theme and then find the below code:

    <?php if (!is_single()) : ?>
    	<figure class="featured-image">
    		<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('the-newsmag-featured-large-thumbnail'); ?></a>
    	</figure>
    <?php else : ?>
    	<figure class="featured-image">
    		<?php if (get_theme_mod('the_newsmag_featured_image_popup', 0) == 1) { ?>
    			<a href="<?php echo $image_popup_url; ?>" class="featured-image-popup" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('the-newsmag-featured-large-thumbnail'); ?></a>
    		<?php } else { ?>
    			<?php the_post_thumbnail('the-newsmag-featured-large-thumbnail'); ?>
    		<?php } ?>
    	</figure>
    <?php endif; ?>

    and replace it with the below code and check:-

    <?php if (!is_single()) : ?>
    	<figure class="featured-image">
    		<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('the-newsmag-featured-large-thumbnail'); ?></a>
    		<?php if (get_post(get_post_thumbnail_id())->post_excerpt) { ?>
    			<span class="featured-image-caption">
    				<?php echo wp_kses_post(get_post(get_post_thumbnail_id())->post_excerpt); ?>
    			</span>
    		<?php } ?>
    	</figure>
    <?php else : ?>
    	<figure class="featured-image">
    		<?php if (get_theme_mod('the_newsmag_featured_image_popup', 0) == 1) { ?>
    			<a href="<?php echo $image_popup_url; ?>" class="featured-image-popup" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('the-newsmag-featured-large-thumbnail'); ?></a>
    		<?php } else { ?>
    			<?php the_post_thumbnail('the-newsmag-featured-large-thumbnail'); ?>
    		<?php } ?>
    		<?php if (get_post(get_post_thumbnail_id())->post_excerpt) { ?>
    			<span class="featured-image-caption">
    				<?php echo wp_kses_post(get_post(get_post_thumbnail_id())->post_excerpt); ?>
    			</span>
    		<?php } ?>
    	</figure>
    <?php endif; ?>

    Hope this works.

    If you like the theme and appreciate the work put on the theme, then, you can help by rating this theme through this link here: https://wordpress.org/support/view/theme-reviews/the-newsmag

    Thanks.
    Bishal Napit

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.