Carlos Florian Carlos Florian - 5 months ago 51
PHP Question

Wordpress image size medium shows different sizes

Thanks for looking here and trying to provide some useful answer. Recently I have downloaded the plugin and it works really fine. But when trying to use the short-code for "Recent Post" i'm facing image-sizing related issue that you see on the image attached below:

enter image description here

It looks really ugly. I opened a code and found the small piece of code for this function:

$out .= '<div class="omsc-recent-posts-title"><h3><a href="'. get_permalink() .'">'. get_the_title() .'</a></h3></div>';

if( $thumbnail && has_post_thumbnail() ) {

$img = wp_get_attachment_image_src( get_post_thumbnail_id(), apply_filters('omsc_sc_recent_posts_img_size', 'medium'));
if($img) {
$img_html=apply_filters('omsc_sc_recent_posts_img', '<a href="'. get_permalink() .'"><img src="'.$img[0].'" alt="'.esc_attr($post->post_title).'" /></a>', array(
'img_src' => $img[0],
'link' => get_permalink(),
'alt' => $post->post_title,
$out.='<div class="omsc-recent-posts-thumb">'.$img_html.'</a></div>';

Then I look on the image size and it says:

$img = wp_get_attachment_image_src( get_post_thumbnail_id(), apply_filters('omsc_sc_recent_posts_img_size', 'medium'));

Checking through FireBug For some posts the "Medium" size is set to 222x221, for others 300x300 and for the rest 222x167

All I want to do is to make all thumbnails having the same size. So, I created this piece of code for my theme's function.php file:

if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'custom-recpost-thumb', 222, 221,true );

and then for the plugin php file I made a call to the function in this way:

$img = wp_get_attachment_image_src( get_post_thumbnail_id(), apply_filters('omsc_sc_recent_posts_img_size', 'custom-recpost-thumb'));

I see the same. Absolutely no changes has been made. What I've done wrong?

Answer Source

the problem as I can see it is that the pictures you upload is not the same dimensions so it will fit your width and make the height auto there are pretty much two ways you can get around this 1. fix your pictures before you upload or fit it with css no.2= make your box that holds your img the width and height that you want and make it overflow hidden then take your image and say it have to be the same height as the box and the width have to be auto the reason for this that most pictures is made as a landscape so in that way your pictures can fit.. for the record it is not a pretty way to do it and I would recommend fixing you pictures before you upload them

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download