Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
Created January 22, 2014 01:17
Show Gist options
  • Save claudiosanches/8551855 to your computer and use it in GitHub Desktop.
Save claudiosanches/8551855 to your computer and use it in GitHub Desktop.
WordPress - Get a first image attachment in post
<?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');
}
@pelukho
Copy link

pelukho commented May 23, 2019

Hello. wp_get_attachment_url() don`t have second parametr 'size'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment