Skip to content

Instantly share code, notes, and snippets.

@patrickgilmour
Created June 28, 2014 14:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save patrickgilmour/2b52f89af50967848c40 to your computer and use it in GitHub Desktop.
Save patrickgilmour/2b52f89af50967848c40 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment