Last active
May 8, 2017 15:07
-
-
Save timmcdaniels/7030653 to your computer and use it in GitHub Desktop.
WordPress Get Image Source Function
This file contains hidden or 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 get_image_src( $id = 0, $size = '', $default_id = 50 ) { | |
$src = ''; | |
// get src of attachment id | |
if ( $id > 0 ) { | |
list( $src, $width, $height ) = wp_get_attachment_image_src( $id, $size ); | |
} | |
// if no src is found and there is a default attachment id, get the source of the default image | |
if ( ! strlen( $src ) && $default_id > 0 ) { | |
list( $src, $width, $height ) = wp_get_attachment_image_src( $default_id, $size ); | |
} | |
return $src; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment