Answers for "wp_get_attachment alt text"

0

wp_get_attachment alt text

First of all you need to get attachment ID for getting alt text..

Use this code to get that,

$img_id = get_post_thumbnail_id(get_the_ID());

Now add your code,

<?php $alt_text = get_post_meta($img_id , '_wp_attachment_image_alt', true); ?>

<h1 class="entry-title"><?php echo $alt_text; ?></h1>
Posted by: Guest on September-27-2021

Browse Popular Code Answers by Language