Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

echo image caption

Retrieve caption of image correct format is

 <?php $post_thumbnail_id = get_post_thumbnail_id( $post_id ); ?> 

<?php

function wp_get_attachment( $attachment_id ) {

    $attachment = get_post( $attachment_id );
    return array(
        'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
        'caption' => $attachment->post_excerpt,
        'description' => $attachment->post_content,
        'href' => get_permalink( $attachment->ID ),
        'src' => $attachment->guid,
        'title' => $attachment->post_title
    );
}

$at= wp_get_attachment($post_thumbnail_id);
print_r($at);//show array of all image detail like title , caption etc

?>

Related Posts:

  1. How to get meta value in wp_attachment_metadata
  2. Removing height and width from images with a caption
  3. Retrieving post meta array (attachment)
  4. How to join Caption AND Description Meta Fields as one combined-caption in Image Block
  5. How to Display Image Caption but Not Alt Text
  6. How do I retrieve the slug of the current page?
  7. Most efficient way to get posts with postmeta
  8. Get posts by meta value
  9. Explanation of update_post_(meta/term)_cache
  10. How to extract data from a post meta serialized array?
  11. How to save an array with one metakey in postmeta?
  12. WordPress is stripping escape backslashes from JSON strings in post_meta
  13. Get Image Description
  14. How can I get the post ID from a WP_Query loop?
  15. Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
  16. How to update_post_meta value as array
  17. Adding meta tag without plugin
  18. What’s the point of get_post_meta’s $single param?
  19. What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
  20. How to edit a post meta data in a Gutenberg Block?
  21. Sanitizing integer input for update_post_meta
  22. post formats – how to switch meta boxes when changing format?
  23. How to have different captions for same image, for galleries?
  24. Execute action after post is saved with all related post_meta records (data)
  25. How to modify an image block in Gutenberg WordPress 5?
  26. Lack of composite indexes for meta tables
  27. Featured image shortcode
  28. Get a single post by a unique meta value
  29. if get_post_meta is empty do something
  30. How we get_post_meta without post id
  31. How get post id from meta value
  32. What is the code to get the download link for a product in WooCommerce?
  33. Safe to delete blank postmeta?
  34. advanced custom fields update_field for field type: Taxonomy
  35. update_post_meta not saving when value is zero
  36. Content hooks vs User hooks
  37. Meta compare with date (stored as string) not working
  38. Trying to get custom post meta through Jetpack JSON API [closed]
  39. How to wrap WordPress image captions inside H2, H3 tags?
  40. How to update/insert custom field(post meta) data with wordpress REST API?
  41. Restrict post edit/delete based on user ID and custom field
  42. get_post_meta returning empty string when data shows in the database
  43. publish_post action hook doesn’t give post_meta_data
  44. Remove WordPress.org Meta link
  45. Remove post meta keys
  46. How to access the post meta of a post that has just been published?
  47. Why time functions show invalid time zone when using ‘c’ time format?
  48. Why is get_post_meta returning an array when I specify it as single?
  49. How to delete outdated, wrongly sized images in _wp_attachment_metadata?
  50. How to update/delete array in post meta value?
  51. How to get all term meta for a taxonomy – getting term_meta for taxonomy
  52. Adding an assisting editor box to Post page
  53. Is there a way to define a default caption to all uploaded images
  54. delete unused postmeta
  55. How to add a link in a image’s caption?
  56. Should I sanitize custom post meta if it is going to be escaped later?
  57. Add post meta based on another post meta value before publish post
  58. Alter media caption/description conflict in WordPress?
  59. Multi-line captions on attachments
  60. How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?
  61. Front-end update_post_meta snippet displays white screen?
  62. Query between two meta values?
  63. Save both current and new version of post meta
  64. How to display a shortcode caption somewhere other than the_content
  65. Caption in Page adding unwanted 10px to width
  66. Get Advanced Custom Fields values before saving [closed]
  67. Give extra post-meta to RSS feeds
  68. WP REST API “rest_no_route” when trying to update meta
  69. Clean up output added via wp_head()
  70. List posts under meta_value heading
  71. Why am I getting an infinite loop with have_posts?
  72. get_post_meta – get a single value
  73. delete value 0 in post meta [closed]
  74. Display info from custom fields in all images’ HTML
  75. Can I safely delete a record, manually, in the wp postmeta table?
  76. How to store post meta in an array?
  77. What action hook updates post meta?
  78. Can’t translate the post meta data (Date) in another language
  79. get_post_meta / update_post_meta array
  80. How to get source of custom meta image?
  81. adding a URL to a post meta
  82. Get post embedded image caption
  83. Exclude a category from the filed under list
  84. copy attachments to another post type and change attachment url
  85. Short of raw SQL, can I query for multiple attachment metadata that have a given array key?
  86. Adjust image caption within visal editor
  87. How do I access post meta data when publishing a new post in Gutenberg?
  88. update_post_meta() not working when used with WordPress action
  89. Drag images with caption in WP editor
  90. Using Advanced Custom Field (ACF) to insert meta description on each page
  91. Triple meta_key on custom SELECT query
  92. get_post_custom()
  93. Adding meta data to an attachment post
  94. update_post_meta not adding anything.(Nor add_post_meta)
  95. loop through all meta keys with get_post_meta
  96. Get posts by meta value with date
  97. How to add meta tag to wordpress posts filter?
  98. Are multiple values from get_post_meta guaranteed to be ordered?
  99. Different captions for the same image in multiple galleries. Edit Image in Gallery locally
  100. Identifying Importer Posts
Categories post-meta Tags captions, images, post-meta, twitter-bootstrap
WordPress ajax success response
Inserting custom data to the_post() during loop

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress