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'm making a custom function for my WordPress site.

function mediumFeaturedImage() {
    if ( has_post_thumbnail() ) { ?>
    <a href="<?php the_permalink(); ?>">
        <?php the_post_thumbnail( 'medium' ); ?>
    <?php } else { ?>                                
    <img src="<?php echo get_template_directory_uri(); ?>/images/no-image.jpg" alt="No Image Given" width="220" height="145"/>
    <?php }

I set the medium size images to 220 x 145 in Settings > Media.

But if you look at the default 'no-image' code block here, I used hard-coded numerals as width="220" height="145". But I want to use this function into some other projects of mine. And I won't use the same settings for medium sized images always. It'll be different from site to site. And always I want my code to be dynamic. Therefore I want a code like this:

<img src="<?php echo get_template_directory_uri(); ?>/images/no-image.jpg" width="<?php $getimagesize('medium','width); ?>" height="<?php $getimagesize('medium','height); ?>"/>

It's not mandatory using a function like me. Is there a built-in code like this, that will grab the sizes I assigned in Media settings in WP-Admin, always?

Or, by using the wp_get_attachment_image_src() how can I grab the width and height of medium size image only, that assigned for medium sized images in Admin panel?


share|improve this question
up vote 2 down vote accepted

I think you want wordpress setting for media

for medium size their are



all setting store in options table.get more media setting

share|improve this answer
Excellent. :) Thanks a lot! – Mayeenul Islam Jun 13 '13 at 11:25

PHP has a function called getimagesize() which returns the an array having width as index 0, height as index 1 and other attributes.

$x = getimagesize('image.jpg');



    [0] => 245 <--width
    [1] => 112 <--height
    [2] => 2
    [3] => width="245" height="112"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
share|improve this answer
Thanks. But that will take the grabbed image size, not the site's Large, Medium and Thumbnail image size declarations. Na? – Mayeenul Islam Jun 13 '13 at 11:27

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.