Skip to content

Instantly share code, notes, and snippets.

@timmcdaniels
Last active May 8, 2017 15:07
Show Gist options
  • Save timmcdaniels/7030653 to your computer and use it in GitHub Desktop.
Save timmcdaniels/7030653 to your computer and use it in GitHub Desktop.
WordPress Get Image Source Function
<?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