- This topic has 32 replies, 2 voices, and was last updated 3 months, 2 weeks ago by
Leo.
-
AuthorPosts
-
March 13, 2015 at 12:46 pm #86463
Michael Jaegers
Hi,
for legal purposes I would like to have the caption of the post thumbnail on the main page visible.
Is this possible?
Best regards,
Michael
March 13, 2015 at 12:49 pm #86468Tom
Lead DeveloperLead DeveloperHi there,
Unfortunately the default WordPress Featured Image only grabs an image – no caption.
Options:
a) Add the caption to the image itself that you’re uploading as the post thumbnail.
b) Try adding the image with the caption code (from the post) into the “Page Header” content area. Then check the “Add to blog excerpt” checkbox.Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 13, 2015 at 1:12 pm #86494Michael Jaegers
Hi Tom,
unfortunately both options do not work.
I saw some code snippets which should do what I need, but I cannot find, where to place them>
<?php echo get_post(get_post_thumbnail_id())->post_post; ?>
Any other idea,
Michael
March 13, 2015 at 11:35 pm #86584Tom
Lead DeveloperLead DeveloperHmm, the above code definitely wouldn’t do it.
You may be able to remove the current post thumbnail with a remove_action call, and then insert your own post thumbnail function in with included code for the caption using a plugin like this: https://wordpress.org/plugins/featured-image-caption/
However, it would involve a decent amount of PHP to do so.
I can look into it further if you like, but I think a or b would still work, and may be better with less hacking into the core theme.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 14, 2015 at 4:59 am #86722Michael Jaegers
Ok, I gave it another try with both options.
I added two pictures and added a title, description and so on to both of them. Now I created two posts (Option A and Option B). For Bption A i added one picture with some fancy guys as post thumbnail. For option B i added the other picture in the Post Header Image field.
Have a look at Jaegers.Net and scroll to January 1st to see the results. Both pictures are visible but no kind of picture description or caption, only for them, which are addid directly to the post content.
Best regards,
Michael
March 15, 2015 at 3:09 pm #87132Tom
Lead DeveloperLead DeveloperHi Michael,
Using Option B (using the page header metabox), why not do something like this?:
<div class="wp-caption alignnone"><img src="http://jaegers.net/wp-content/uploads/2015/03/IMG_0003.jpg" alt=""><p class="wp-caption-text">Your caption here</p></div>
You would add the above to the “Content” field, and then update the image URL and caption.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 15, 2015 at 11:43 pm #87226Michael Jaegers
Hmm, it’s working, but it’s also an ugly solution as there are many manual actions required per post.
March 16, 2015 at 10:47 pm #87719Tom
Lead DeveloperLead DeveloperFair 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 } }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 18, 2015 at 1:53 pm #88330Michael Jaegers
Hi Tom,
thank you for your support. Sorry, I didn’t want to annoy you. I really appreciate your excellent and quick support! For me it’s ok so far.
Best regards,
Michael
March 18, 2015 at 5:00 pm #88387Tom
Lead DeveloperLead DeveloperNo problem! The more options the better! π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 16, 2015 at 5:37 pm #99318Emily Condit
Hi.
I’m having an issue with not being able to set a caption for my featured image as well. I downloaded and installed the plugin you mentioned but I don’t see the code you’re referring to in the plugin code. Am I looking in the right place?
Thanks!
π EmilyApril 16, 2015 at 10:41 pm #99347Tom
Lead DeveloperLead DeveloperHi Emily,
The code above can go into your child theme’s functions.php file – you can learn more about adding PHP here: http://generatepress.com/knowledgebase/adding-php-functions/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 16, 2015 at 11:08 pm #99362Emily Condit
Hi, Tom.
So I have added the plugin you suggested and downloaded the child theme and am using it. I put your code in the functions.php file. You can see the result here: cafeemily.com
The post thumbnails are being duplicated as well as the thumbnail captions on the duplicate image.
What I want is to be able to display the image caption for the thumbnails AND have them display on the large post image in the post itself. Right now, the caption is only showing up for the thumbnails which the plugin was doing before I added your code.
I can obviously remove the code you gave me and get rid of the duplicate problem but I would really like to display the captions on the actual image inside the post itself.
I really appreciate your help. You don’t have to do this but it makes my life a lot easier. I have coding experience but I’m not nearly as knowledgeable about the WordPress framework as you are.
Thanks!
π EmilyApril 16, 2015 at 11:20 pm #99368Tom
Lead DeveloperLead DeveloperLooks like you’re using the blog add-on, which requires a slightly different function to remove the initial one:
add_action('after_setup_theme','generate_remove_blog_post_image'); function generate_remove_blog_post_image() { remove_action( 'generate_after_entry_header', 'generate_blog_post_image' ); }
Hopefully that does it for you π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 17, 2015 at 12:37 pm #99615Emily Condit
Hi, Tom.
Not sure what happened but I got a parse error on line 9 when I replaced the old remove function with the new one. This is what my functions.php looks like. Maybe you can tell me what the problem is?
<?php /** * Generate child theme functions and definitions * * @package Generate */ add_action('after_setup_theme','generate_remove_blog_post_image'); function generate_remove_blog_post_image() { remove_action( 'generate_after_entry_header', 'generate_blog_post_image' ); } 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 } }
Thanks!
π Emily -
AuthorPosts
- The topic ‘Caption for post thumbnails’ is closed to new replies.