Last Updated: February 25, 2016
·
4.551K
· pimschaaf

WordPress post thumbnail alt

Easy access to the post thumbnail alt text by post ID.

function get_the_post_thumbnail_alt($post_id) {
    return get_post_meta(get_post_thumbnail_id($post_id), '_wp_attachment_image_alt', true);
}

function the_post_thumbnail_alt($post_id) {
    echo get_the_post_thumbnail_alt($post_id);
}