Skip to content

Instantly share code, notes, and snippets.

@patrickgilmour
Created June 28, 2014 14:20
Show Gist options
  • Save patrickgilmour/2b52f89af50967848c40 to your computer and use it in GitHub Desktop.
Save patrickgilmour/2b52f89af50967848c40 to your computer and use it in GitHub Desktop.

Revisions

  1. patrickgilmour created this gist Jun 28, 2014.
    24 changes: 24 additions & 0 deletions wp-get-image-alt-text.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    <?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;

    }