Description of an image in Wordpress

1

Good morning,

I am trying through a WP template tag to get the description of a specific image. I've tried the_title () and it just takes the title.

How can I get the caption (description) of an image I have in the library?

Thank you!

    
asked by Raúl 11.09.2017 в 23:37
source

1 answer

0

You can get the different elements of the image in this way:

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
    );
}

Source: Wordpress.org

    
answered by 11.09.2017 / 23:50
source