treehouse : what would you like to learn today?
Web Design Web Development iOS Development

img alt text?

  • Is the img alt text possible with this current code?

    <?php  if((get_post_meta($post->ID, "image", true))) { ?>
    <img src='/images/<?php echo get_post_meta($post->ID, "image", true); ?>' />
    <?php } ?>
  • What about something like this?
    <?php  if((get_post_meta($post->ID, "image", true))) { ?>
    <img alt='<?php the_title(); ?>' src='/images/<?php echo get_post_meta($post->ID, "image", true); ?>' />
    <?php } ?>
  • That might be my only option. I wanted to match the alt text in the backend, but so far no luck. I tried this.

    <img alt='<?php get_post_meta($post->ID, '_wp_attachment_image_alt', true); ?>
  • Oh, check out the_post_thumbnail() and the arguments you can pass. It has the answer there.
  • Thanks!