Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Gabriel Ward
Gabriel Ward
20,222 Points

Setting correct size of images in Wordpress

I'm trying to build a Wordpress theme from scratch. I have my static template working as I want it to. The images are correctly proportioned in size and are responsive as they should be. But when I come to set thumbails for the pictures in the Wordpress theme the sizing is all off. The images resize independent of the window when I change the window size, and the proportions change as well. Any tips would be greatly appreciated. I've played around with set_thumbail_size in functions.php but no luck so far.

1 Answer

Jacobus Hindson
Jacobus Hindson
14,429 Points

You can change the thumbnail size in the WordPress Admin GUI, under Settings>Media. If you change the size of them you need to regenerate thumbnails in order for the change to occur, you can do this with a plugin or by re-uploading them to the server.

Gabriel Ward
Gabriel Ward
20,222 Points

Hmm ok, this is my code in functions.php

add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150 );

Before adding the set post thumbnail size I deleted the photos and then uploaded them again after adding the code. Still no luck. The photos are cropped and stretched something awful. What are your thoughts? Thanks for your help.

Jacobus Hindson
Jacobus Hindson
14,429 Points

This sets a rigid 150,150 so unless your images are square to begin with you are going to suffer from distortion. There are options regarding cropping, resizing and alignment available for use with set_post_thumbnail_size in the codex.

Gabriel Ward
Gabriel Ward
20,222 Points

Ok and I'm correct in thinking that you set this in functions.php?