• Can I add the “title” or “alt” tag and have it load for each thumbnail image, the title of the post?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter antoniopaim

    (@antoniopaim)

    Thanks!

    In fact I have problems, because users don’t fill in the “alt” tag and WP is taking the file name and automatically putting it in the “alt” and “title” tag of the image.

    As a quick fix, as there are millions of images, I need the “alt” or “title” tag to be filled with the post title. It’s one image per post only.

    I tried like this… but without success

    the_post_thumbnail( ‘thumbnail’, [ ‘alt’ => esc_html ( the_title() ) ] ); or

    the_post_thumbnail( ‘thumbnail’, [ ‘alt’ => esc_html ( get_the_title() ) ] );

    Where are you adding this code? This code should help…or point you in the right direction:

    <?php
    $image = get_the_post_thumbnail( null, 'thumbnail', [ 'alt' => esc_attr( get_the_title() ), 'title' => '' ] );
    echo $image;
    ?>
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘the_post_thumbnail with tag alt or title’ is closed to new replies.