0

There are previously-asked questions but either they don't work with my theme or I'm too stupid to figure them out.

Essentially my chunk of code is below and I'm using the Avada WordPress theme (you might have heard of it). I'm using a child theme. I'm trying to boost my SEO and Google tells me that I need alt text for my featured images (well, all images, but I'm starting here). As opposed to editing 2500 images in all of my reviews, figured it'd be easier to do it via code.

Can someone modify this for me so that it works?

<li>
<?php if ( Avada()->settings->get( 'status_lightbox' ) && Avada()->settings->get( 'status_lightbox_single' ) ) : ?>
<a href="<?php echo esc_url_raw( $attachment_data['url'] ); ?>" data-rel="iLightbox[gallery<?php the_ID(); ?>]" title="<?php echo esc_attr( $attachment_data['caption_attribute'] ); ?>" data-title="<?php echo esc_attr( $attachment_data['title_attribute'] ); ?>" data-caption="<?php echo esc_attr( $attachment_data['caption_attribute'] ); ?>" aria-label="<?php echo esc_attr( $attachment_data['title_attribute'] ); ?>">
                                                <span class="screen-reader-text"><?php esc_attr_e( 'View Larger Image', 'Avada' ); ?></span>
                                                <?php echo get_the_post_thumbnail( $post->ID, 'full' ); ?>
                                            </a>
                                        <?php else : ?>
                                            <?php echo get_the_post_thumbnail( $post->ID, 'full' ); ?>
                                        <?php endif; ?>
                                    </li>
1
  • On the HTML side of things, I'd essentially like to see something like this: <img src="whatver.jpg" alt="Post Title">
    – user34872
    Sep 2, 2018 at 20:59

1 Answer 1

0

You can replace :

<?php echo get_the_post_thumbnail( $post->ID, 'full' ); ?>

with this:

<?php echo get_the_post_thumbnail( $post->ID, 'full' , array( 'alt' => get_the_title() )  ); ?>

to set the post tile as the alt attribute for the image

Your Answer

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

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