skip to Main Content

I have a piece of code for wordpress attachment page

$image_size = apply_filters( 'wporg_attachment_size', 'large' );
    echo wp_get_attachment_image( get_the_ID(), $image_size );

it woks fine and show the image with everything including Alt,
but I want to show attachment ALT text below the image.
what should I use?
like this image:

enter image description here

2

Answers


  1. Use wp_get_attachment_image_url with img tag.

    <img src="<?php echo wp_get_attachment_image_url(get_the_ID(), $image_size); ?>" alt="Text" />
    
    Login or Signup to reply.
  2. You can display just the alt text below your image seperately by getting the alt text from the post within the DB.

    <?php echo get_post_meta(get_the_ID(), '_wp_attachment_image_alt', true); ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search