Skip to content

Instantly share code, notes, and snippets.

@rossharper
Created March 21, 2012 20:43
Show Gist options
  • Save rossharper/2152690 to your computer and use it in GitHub Desktop.
Save rossharper/2152690 to your computer and use it in GitHub Desktop.
Getting an article image on WordPress
<?php
function rh_article_image()
{
// If there is an image attached to the post...
if(has_post_thumbnail())
{
// .. get its uri and echo it
$imgarr = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full', false );
echo $imgarr[0];
}
else // otherwise, use the theme's header image
{
// Echo the theme's header image
// header_image();
// My theme doesn't use a header image, so I use the theme's hardcoded banner image
echo get_theme_root_uri() . '/' . get_current_theme() . '/images/banner.jpg';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment