patrickgilmour
6/28/2014 - 2:20 PM

WordPress Images - echo the Alt text of the Featured image (and other image attributes)

WordPress Images - echo the Alt text of the Featured image (and other image attributes)

<?php

/**
 * Get the Alt text of a Featured Image
 *
 * And other image attributes
 */
add_action('genesis_before_sidebar_widget_area', 'pgwp_genesis_before_sidebar_widget_area' );
function pgwp_genesis_before_sidebar_widget_area () {

	$img_id = get_post_thumbnail_id( get_the_ID() ); //Note: you may need other methods to get id

  $alt_text = get_post_meta( $img_id, '_wp_attachment_image_alt', true  );

  if(count( $alt_text ))
    echo $alt_text;
	
	
	// Show other image attributes, using get_post() - different from above
  // echo get_post( get_post_thumbnail_id() )->post_title;
  // echo get_post( get_post_thumbnail_id() )->post_excerpt;
  // echo get_post( get_post_thumbnail_id() )->post_content;
	
}