Created
March 21, 2012 20:43
-
-
Save rossharper/2152690 to your computer and use it in GitHub Desktop.
Getting an article image on WordPress
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 | |
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