Skip to content

Instantly share code, notes, and snippets.

@DediData
DediData / wordpress-post-thumbnail-or-first-image-or-default.php
Last active September 17, 2017 12:52 — forked from brajeshwar/wordpress-post-thumbnail-or-first-image-or-default.php
Wordpress - Get the Image from Post Thumbnail or the First Image of a post or else use a default Image.
<?php
/*
* 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 get_post_image_url(); ?>
*/
function get_post_image_url($size = 'full') {
if (has_post_thumbnail()) {
$image_id = get_post_thumbnail_id();