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 try to get thumbnail URL correctly...

In my functions.php, I have theses lines:

add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 'emphasis', 132, 82, true );
function w_thumbnail_src() {
    if (has_post_thumbnail()) {
        $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'emphasis');
       echo $thumb[0]; // thumbnail url

The thing is, I don't get the correct size in my template :( I have this:

<?php w_thumbnail_src(); ?>

That returns the big image, not the thumbnail :(

Where am I wrong?

Regards, Alex

share|improve this question
up vote 0 down vote accepted

You are not using set_post_thumbnail_size properly. Try with:

add_image_size( 'emphasis', 132, 82, true );
share|improve this answer
I see... Big thanks. What if I don't want to refer to the size in the function, but in the template itself? So I can use the same function for different image size? And set in my template, something like: <?php w_thumbnail_src('emphasis'); ?> Big thanks anyway :) – flintsburg Nov 21 '11 at 16:54
You may use the following modified code: function w_thumbnail_src($size = 'thumbnail') { if (has_post_thumbnail()) { $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), $size); echo $thumb[0]; // thumbnail url } } You may pass the desired size, and if you don't it will use the default thumbnail size. – marcochiesi Nov 21 '11 at 18:08
Many thanks Marco. It's working perfectly. And now, I understand how to create "dynamic" functions. So thank you :) – flintsburg Nov 21 '11 at 18:44

You are using the wrong function to set the size of the image. You want to use add_image_size('emphasis', 132, 82, true ); set_post_thumbnail_size() sets the default post thumbnail size and does not accept a name attribute.

share|improve this answer

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.