njhelloworld
njhelloworld

Reputation: 147

get the specific title attribute of wordpress image

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

Answers (2)

Ravinder Kumar
Ravinder Kumar

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

Ferrmolina
Ferrmolina

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

Related Questions