I seem to have a problem trying to display the "alternative text" of the featured image.

Here is the code that I have been working on. Not sure why the alternative text is showing blank.


        $projects = new WP_Query( array( 'post_type' => 'print-billboard' ) );
        if ( $projects->have_posts() ) : while ( $projects->have_posts() ) :


            $featured_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
            $featured_image_url = wp_get_attachment_url( get_post_thumbnail_id() );
            $alt = get_post_meta( $featured_image, '_wp_attachment_image_alt', true );
            if ( has_post_thumbnail() ) :


            <a href="<?php echo $featured_image_url; ?>" id="post-<?php the_ID(); ?>" <?php post_class( 'four columns project-post fancybox' ) ?> >

                <?php $thumbnail_meta = get_post_meta( $featured_image, '_wp_attachment_image_alt', true ); ?>

                <figure class="full-width featured-image">
                    <img src="<?php echo $featured_image[0]; ?>" data-fancybox-group="gallery" title="Lorem ipsum dolor sit amet" alt="<?php echo $featured_image; ?>" />
                    <div class="overlay">


            <?php endif; ?>

        <?php wp_reset_postdata(); ?>

        <?php endwhile; else: ?>

        <p class="error-message">No Projects</p>

        <?php endif; ?>

        <?php wp_reset_query(); ?>

2 Answers 2


I am not so sure of what I am going to say, but from a fast look, $featured_image is an array (URL, width, height, is_intermediate). so assuming that your alternative text exists in this array, you need to specify its index like this: $featured_image[index_of_alt_text] according to my understanding, the $featured_image array doesn't contain your alternative text or you didn't specify the index.

I hope it helped

 if ( $projects->have_posts() ) : while ( $projects->have_posts() ) :

/*****     Thumbnail     ******/
        array(120, 90),     //Size of the thumbnail Image

            'class' => 'class_name',     //Specify class name to thumbnail image if any
            'alt' => 'post thumbnail',   // alternate text in case if no thumbnail image to show
            'title' => 'Notice'          //Specify title if want to
/*******     Thumbnail Ends   ********/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.