WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use this plugin to echo the URL of a post's featured image in the header:

/** Plugin Name: Post Thumbnail FB header */
function fb_header()
    // Not on a single page or post? Stop here.
    if ( ! is_singular() )

    $post_ID = get_queried_object_id();

    // We got no thumbnail? Stop here.
    if ( ! has_post_thumbnail( $post_ID ) )

    // Get the Attachment ID
    $att_ID = get_post_thumbnail_id( $post_ID );

    // Get the Attachment
    $att    = wp_get_attachment_image_src( $att_ID );

         '<link rel="image_src" href="%s" />'
        ,array_shift( $att )
add_action( 'wp_head', 'fb_header' );

As it stands currently, it echo's the featured image. I want it to echo the URL of the Large version of the featured image. How can I do this? Just to note that all my featured images have a large version...

share|improve this question
up vote 2 down vote accepted

Use the second parameter of wp_get_attachment_image_src(): $size.

$att    = wp_get_attachment_image_src( $att_ID, 'large-thumb' );


$att    = wp_get_attachment_image_src( $att_ID, array ( 900, 300 ) );

The size is passed to image_downsize() and there to image_get_intermediate_size(). If $size is an array WordPress will search for the best match in existing images:

// from wp-includes/media.php::image_get_intermediate_size()
// get the best one for a specified set of dimensions
if ( is_array($size) && !empty($imagedata['sizes']) ) {
    foreach ( $imagedata['sizes'] as $_size => $data ) {
        // already cropped to width or height; so use this size
        if ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) {
            $file = $data['file'];
            list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
            return compact( 'file', 'width', 'height' );
share|improve this answer
Can you please elaborate on the 900, 300? Does it search for those dimensions? – Amanda Bynes Oct 31 '12 at 18:05
@AmandaBynes See my update. – toscho Oct 31 '12 at 18:09
@torscho I tested your first code, adding large-thumb to the line and it did not work. It returned the full image and not the large thumb. Is there any way you can confirm that it works for you? – Amanda Bynes Oct 31 '12 at 18:18
large-thumb was just an example. You have to add the image size in your theme first. See also add-image-size. – toscho Oct 31 '12 at 18:21
Got it - thank you for the info! – Amanda Bynes Oct 31 '12 at 18:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.