NapitWPTech Theme Support › Forums › The NewsMag › Featured image caption
Tagged: caption, featured image
This topic contains 1 reply, has 2 voices, and was last updated by Bishal Napit 11 months, 1 week ago.
- AuthorPosts
- 24/05/2017 at 22:12 #229
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.
25/05/2017 at 06:41 #230Hi 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 - AuthorPosts
You must be logged in to reply to this topic.