Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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' ); ?>
    </a>
    <?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?

Possible?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I think you want wordpress setting for media

for medium size their are

get_option('medium_size_w');//width

get_option('medium_size_h');//height

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');

print_r($x);

Output:

Array
(
    [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

 
discard

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.