Created
June 28, 2014 14:20
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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