Reputation: 147
I would like to ask how to get the specific title attribute of wordpress image from wordpress media?
Those information that are being inputted upon uploading the images life, title, alt captions, description.
Upvotes: 1
Views: 3881
Reputation: 944
You can find specific attribute of wordpress image attachment.
<?php
$attachment_id = 8; // attachment ID
$image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array
if( $image_attributes ) {
?>
<img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
<?php } ?>
An array containing:
[0] => url
[1] => width
[2] => height
[3] => boolean: true if $url is a resized image, false if it is the original or if no image is available.
Upvotes: 1
Reputation: 2771
This should help you.
$title = get_post(get_post_thumbnail_id())->post_title; // Title
$caption = get_post(get_post_thumbnail_id())->post_excerpt; // Caption
$description = get_post(get_post_thumbnail_id())->post_content; // Description
Upvotes: 1