A specialist in WordPress and Content Management Systems for Business Websites and eCommerce Solutions.
Read more »
Check out my most recent project →
Here’s a quick and easy way to update image sizes on the fly directly in your Wordpress posts. Add this code into your functions.php file in your theme. Then make sure you insert timthumb.php in the root of your theme directory. Next create a fully writable directory named ‘cache’ and place that in your theme root directory.
Now inside your posts just wrap an image URL with the img shortcode. Add height, width, alt, and class to it for more flexibility.
1 2 3 4 5 6 7 8 9 10 11 12 | // Image resize in content // To Use: [img w=600 h=200 class=alignleft alt=My Photo]http://mysite.com/photo.jpg[/img] function timmyimg($atts, $content = null) { extract(shortcode_atts(array( 'w' => '600', 'h' => '250', 'class' => 'alignnone', 'alt' => '' ), $atts)); return "<img src='". get_bloginfo('template_directory') . "/timthumb.php?src=".$content."&w=".$w."&h=".$h."' alt=".$alt." class='wp-post-img ".$class."' />"; } add_shortcode('img', 'timmyimg'); |
TimThumb PHP Script is a custom image-sizing script, that allows you to produce a cropped and sized version of an image. These are great to use along with a Wordpress Magazine Theme. TimThumb has recently been released as open source, and here I will walk you through adding TimThumb to your Wordpress theme. (more…)