Get the attachment ID and convert to a post. From there the caption is stored on the post object.
$thumb_img = get_post( get_post_thumbnail_id() ); // Get post by ID
echo $thumb_img->post_excerpt; // Display Caption
echo $thumb_img->post_content; // Display Description
In your loop it would look like:
<?php if($gallery) : ?>
<?php foreach($gallery as $key => $value) :
$image = wp_get_attachment_image_src($value);
$image_post = get_post($value);
$caption = $image_post->post_excerpt;
How you want to output the value depends on you and your css expectations;
<p class="wp-caption-text"><?php echo $caption; ?></p>
An alternate would be to use Caption_Shortcode:
<image> Caption
Related Posts:
- Update caption for metabox gallery images
- How to show post format gallery metabox image caption in the post front end
- How to insert Gallery shortcode to a meta box
- custom meta box data not saved
- How to generate a featured image from a video embeded in a metabox
- Hide meta box based on post format
- How to add meta box for current post format?
- Unable to save multiple images in wordpress
- Remove Title, Editor and Meta Box Support Based on Post Formats
- What is the “Advanced” $context in add_meta_box?
- Creating a metabox to upload multiple images
- Post custom metabox textarea using wp_editor
- How do I get attachment_id?
- Removing Metabox for “Slug” without removing functionality
- Prevent sorting and dragging of specific postbox metabox
- How to have different captions for same image, for galleries?
- Removing meta boxes: remove-meta_box() or unset()?
- CMB2 metabox conditional logic
- How to pass variable via $callback_args for add_meta_box
- Undefined function error when creating Custom Meta Box
- Move excerpt to always be directly below post content in admin
- Getting the ID of a meta box
- Custom filter for the_content doesn’t work correctly
- Check if meta key value already exists
- Is there a predefined callback function for custom categories?
- Conditional Meta Boxes
- Why is `add_meta_box` not working?
- How to access global $wp_meta_boxes variable on front-end?
- prevent post submission
- How do I display Youtube/Vimeo video ID on custom post type when user enters it in custom meta box?
- Position right sidebar metabox right below the publish metabox?
- WordPress media manager multiple selection output
- metabox upload file
- Are there any standard HTML markup for metabox?
- Can not pass the value of google pie chart from custom meta box
- Dynamically adding WYSIWYG to metaboxes
- Filter Hook Returning Blank When Used Twice
- Why does get_post_meta not work with the posts page?
- Taxonomy as checkboxes
- What are ‘authors’ in WordPress, and is there an author ‘metabox class’ available anywhere?
- Trying to limit access to custom meta box without success
- Setting multiple image urls using WordPress’ Media Uploader
- Custom metabox field help tips popups
- Getting gutenberg (WordPress 5) to save TInymce data?
- Adding metabox to wordpress plugins menu page
- Edit woocommerce product post type
- Set default value for radio button in WP Alchemy custom meta box?
- quicktags “link” button doesn’t work, but all other buttons do
- How do wordpress hooks respond to user interaction?
- Add custom action in post type
- PHP Notice: Undefined index: mytheme_meta_box_nonce
- Save meta value as an array of arrays
- Polylang not translating Metabox fields [closed]
- Global Variable vs Local Variable
- input radio ‘checked’ saves, but select option ‘selected’ doesn’t
- save_post_{$post->post_type} action firing on second save
- Add a metabox when editing a media – but only for images
- edit_page or edit-pages for current_user_can()?
- Save meta data with post, Without using any plugin [closed]
- Metabox not being added
- Editor meta box Showing but not saving
- Adding a metabox shortcode “paypal accept payment” in my custom post type back-end
- The $post variable – Did I get the grasp of how the Backend actions get parsed?
- Change the title of an Administration Panel
- display metabox on front end (my-metabox-class)
- Custom Meta Box calling JS function twice
- how to reset metabox excerpt to open
- Post and Pages section inside WordPress admin are completely blank
- How to create a custom metabox like the wordpress provided tag metabox?
- Update Post meta with custom variable
- How to alter static Page text through the Theme Customizer API
- Moving a metabox – not obeying context or removing old
- Programmatically create new post from a metabox button
- Saving metabox content not working
- semantic ui dropdown for custom metabox
- How to hide/show meta box using jQuery,if click on Drop-Down Menu
- Get value from meta box
- Adding Meta Box to Specific Submenu Page
- How do I change the woocommerce product gallery to show all thumbnails instead of three at a time in a carousel?
- jQuery UI Sortable not Working With Metabox
- Multiple category filters
- meta_box: update_post_meta for
- Issue with file paths after porting metabox from main theme to child theme
- Error in get post by met_key
- Custom meta box not saving values of radio buttons in WordPress
- Display multiple “save draft button” on a post edit
- Serialization problem after auto-update
- Selecting a dynamic sidebar via metabox in wordpress
- Add additional metafields based on value of select box
- Issues with Saving Dynamic Metabox
- Updating post meta and Meta Box plugin
- Related posts and custom meta_box?
- header specific meta box result detect url
- Meta Boxes causing Header errors
- Attaching a metabox to a single post
- Adding different classes to different images depending on size for fine control of image layout in posts
- How do I allow Authors and Contributors to use the metabox
- CSS styling not working in a custom metabox
- CPT posts in drop downed in meta box on page doesn’t return post ID
- How to make remove display none to this div container in post meta box?