how do i retrieve and display the alt text of an image in wordpress? trying to substitute the title for the alt. here is the original code.
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
so in the h1 i want:
<h1 class="entry-title">"alt text of image"</h1>
tried putting it in a variable like so:
$alt_text = get_post_meta($img_id , '_wp_attachment_image_alt', true);
<h1 class="entry-title"><?php echo $alt_text; ?></h1>
but it doesn't show up. any solutions?
$img_id
is correct? – Maxime Lorant Feb 21 '14 at 21:26