Support » Fixing WordPress » Retrieve Featured Image Metadata (Title, Caption, Alt Text, Description)

Viewing 1 replies (of 1 total)
  • I found the answer, so if anyone else is looking for this, here it is:

    WordPress stores each image as its own post. The title of the image is the title of the post, the caption of the image is the excerpt and the description of the image is the content of the post.

    So you can assign each of these to variables like this (code must be placed inside the loop):

    $title = get_post(get_post_thumbnail_id())->post_title; //The Title

    $caption = get_post(get_post_thumbnail_id())->post_excerpt; //The Caption

    $description = get_post(get_post_thumbnail_id())->post_content; // The Description

    Once again, apologies if this has been done to death already – it took me ages to find the answer.

    I found the solution here:

    How to Display WordPress Post Thumbnails with Captions

Viewing 1 replies (of 1 total)
  • The topic ‘Retrieve Featured Image Metadata (Title, Caption, Alt Text, Description)’ is closed to new replies.