How To Change The Default Image Sizes in Media Settings With functions.php

by WebMinimalist.com on Jul 31, 2012
in Wordpress TutorialNo Comment


Add a code check to stop these from being changed:

//Check and Set the Default Thumbnail Sizes
if(get_option('thumbnail_size_w')!=160)update_option('thumbnail_size_w',160);
if(get_option('thumbnail_size_h')!=80)update_option('thumbnail_size_h',80);
if(get_option('medium_size_w')!=640)update_option('medium_size_w',640);
if(get_option('medium_size_h')!=320)update_option('medium_size_h',320);
if(get_option('large_size_w')!=1280)update_option('large_size_w',1280);
if(get_option('large_size_h')!=640)update_option('large_size_h',640);

Then they can be called with get_the_post_thumbnail:

$id=$post->ID;
get_the_post_thumbnail($id, 'thumbnail'); // Thumbnail
get_the_post_thumbnail($id, 'medium'); // Medium resolution
get_the_post_thumbnail($id, 'large'); // Large resolution
get_the_post_thumbnail($id, array(480,240) ); // Other resolutions

References:
WordPress.org Forums

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>