Skip to content

Instantly share code, notes, and snippets.

View martinodehnal's full-sized avatar

Martin Odehnal martinodehnal

View GitHub Profile
@brajeshwar
brajeshwar / wordpress-post-thumbnail-or-first-image-or-default.php
Created September 9, 2011 10:23
Wordpress - Get the Image from Post Thumbnail or the First Image of a post or else use a default Image.
/*
* Display Image from the_post_thumbnail or the first image of a post else display a default Image
* Chose the size from "thumbnail", "medium", "large", "full" or your own defined size using filters.
* USAGE: <?php echo my_image_display(); ?>
*/
function my_image_display($size = 'full') {
if (has_post_thumbnail()) {
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id, $size);