Created
January 22, 2014 01:17
-
-
Save claudiosanches/8551855 to your computer and use it in GitHub Desktop.
WordPress - Get a first image attachment in post
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 odin_get_first_image() { | |
$attachment = get_children( | |
array( | |
'post_parent' => get_the_ID(), | |
'post_type' => 'attachment', | |
'post_mime_type' => 'image', | |
'order' => 'DESC', | |
'numberposts' => 1, | |
) | |
); | |
if ( ! is_array( $attachment ) || empty( $attachment ) ) { | |
return; | |
} | |
$attachment = current( $attachment ); | |
echo wp_get_attachment_url( $attachment->ID,'full'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello.
wp_get_attachment_url()
don`t have second parametr 'size'