get all the details and display of WP gallery Image ie: caption, description, etc.
//in your functions.php
function wp_get_attachment_image( $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
);
}
//Then you can just pass in the id and get whatever details/meta you need like this: $attachment_meta_caption = wp_get_attachment_image(your_attachment_id);
//display image caption name
echo $attachment_meta_caption[‘caption’];
-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com
//in your functions.php
function wp_get_attachment_image( $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
);
}
//Then you can just pass in the id and get whatever details/meta you need like this: $attachment_meta_caption = wp_get_attachment_image(your_attachment_id);
//display image caption name
echo $attachment_meta_caption[‘caption’];
-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com
No comments:
Post a Comment