WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Post Thumbnails
Alt tags (2 posts)

  1. dturnbot
    Member
    Posted 1 year ago #

    I'm using picturefill images to create a responsive layout.
    I have the image url in a variable using get_post_thumbnail_url().

    How I could retrieve the alt tag in a variable.

    http://wordpress.org/extend/plugins/multiple-post-thumbnails/

  2. Chris Scott
    Member
    Plugin Author

    Posted 1 year ago #

    Since there's no helper in WP to get the alt attribute, you'd have to do something like:

    attachment_id = MultiPostThumbnails::get_post_thumbnail_id( $post_type, $id, $post_id );
    $alt = '';
    $alt = trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
    
    if ( ! $alt ) {
      $attachment = get_post( $attachment_id );
      $alt = trim(strip_tags( $attachment->post_excerpt )); // Use Caption
      if ( ! $alt ) {
          $alt = trim(strip_tags( $attachment->post_title )); // Use Title
      }
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic