- This topic has 12 replies, 3 voices, and was last updated 3 years, 5 months ago by Leo.
-
AuthorPosts
-
February 3, 2019 at 8:02 pm #800591Simon
Hello,
I would like to display the image caption automatically on the articles, I use the unsplash site and I should display the credits on the images used.
I would like to display them just above the content or above the widget bar, how can I do that?
I tried the shared codes on this post: https://generatepress.com/forums/topic/caption-for-post-thumbnails/ but none of them work.
Sorry about my English, I use a translator.
Thank you.February 4, 2019 at 6:05 am #800893DavidStaffCustomer SupportHi there,
you can use the Hook Element:
https://docs.generatepress.com/article/hooks-element-overview/
Add this snippet:
<?php $get_description = get_post(get_post_thumbnail_id())->post_excerpt; if(!empty($get_description)){ echo '<div class="featured_caption">' . $get_description . '</div>'; } ?>
Choose which Hook you want to use:
https://docs.generatepress.com/article/hooks-visual-guide/#posts-pageCheck Execute PHP
And set your Display Rules for where the featured images are being used.
February 4, 2019 at 7:55 am #801100SimonThe php execution was disabled on my server.
I hadn’t seen the hooks page, it works perfectly:)
Thanks for the support.
February 4, 2019 at 8:21 am #801126DavidStaffCustomer SupportGreat to hear. Glad to be of help.
October 27, 2020 at 3:24 am #1505898SagarI want to show featured image caption on all my blog posts.
https://docs.generatepress.com/article/hooks-visual-guide/#single-post
I want to show the caption after the featured image, not before that in the single blog posts.
How to do that?
October 27, 2020 at 3:26 am #1505900SagarLike this news website has given
https://www.hindustantimes.com/it-s-viral/dad-s-complete-guide-to-baby-video-is-absolutely-hilarious-watch/story-opDXsEccg885ZFQXLnWooL.htmlThe caption is: “The image shows a shot from the video. (Instagram/@howtodadnz)”
October 27, 2020 at 5:21 am #1506029DavidStaffCustomer SupportHi there,
add this PHP Snippet:
add_action( 'post_thumbnail_html', 'tu_custom_byline', 10 ); function tu_custom_byline( $html ) { if ( is_single() ){ $html .= '<div class="wp-caption">Your Caption Here</div>'; } return $html; }
https://docs.generatepress.com/article/adding-php/
Then some CSS to style it:
.featured-image .wp-caption { padding: 10px 0; text-align: left; }
If you need any further assistance, please raise a new topic where you can share a link to your site.
October 27, 2020 at 6:32 am #1506114SagarHi,
This code will show the caption in all of my blog posts? Or do I need to enter this code on each blog post or something?
I want if I enter the caption in any of the blogs featured images, it should come automatically without entering the code every time.
Please guide me.
October 27, 2020 at 7:43 am #1506237DavidStaffCustomer SupportYou only need to add that code once.
Follow the instructions provided here:October 27, 2020 at 8:57 am #1506601SagarI don’t want to use any plugin. I’m doing that through hook element > enabled Execute PHP with the above code you have given and generate_after_entry_header hook. Still not working
October 27, 2020 at 9:59 am #1506689LeoStaffCustomer SupportDavid’s code would only work if you add it using one of these methods:
Adding PHP: https://docs.generatepress.com/article/adding-php/Code snippets plugin is the easiest way and should have minimal impact on your site – we use it all the time.
The only other option is to use a child theme and add the code in the
function.php
file:
https://docs.generatepress.com/article/using-child-theme/If you need more help with this, please open a new topic.
October 27, 2020 at 11:19 am #1506827SagarThen what is the use of having this hook element? Why don’t we add it through that?
October 27, 2020 at 11:22 am #1506837LeoStaffCustomer SupportHooks allow you to add content in specific spots (hooks) throughout the theme.
post_thumbnail_html
is not a hook.Please open a new topic if you need further help with this.
Thank you.
-
AuthorPosts
- The topic ‘Display image caption on the featured image’ is closed to new replies.