Resize Images using Shortcode with TimThumb

TimThumb is wonderful image re-sizer so far, with TimThumb we can easily re size image on the fly. Without any worries. TimThumb support cache so load our server more stable. On today WordPress Tricks I will show you nicely tricks from Chad Coleman. Integrated TimThumb with Shortcode and make re size image more easy and useful.

Create WordPress Shortcode with Coda

Create WordPress Shortcode with Coda

We need to re write this code on our functions.php, then you can use it in our post content using shortcode. Please noted you need to put your TimThumb script on your themes folder. Let’s get started, open your functions.php and re write this code

// Image resize in content
function timmyimg($atts, $content = null) {
		'w' => '540',
		'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');

Then save it, this code have default width and height size, on this example the default width is 540 and default height 250. How to use TimThumb shortcode? It’s easy. Check this example below

[img w=540 h=200 class=alignleft alt=My Photo][/img]

That’s it, you can use this shortcode More than one in single post. Thanks for Chad Coleman for this tutorial.

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @JauhariNET on twitter for latest updates.

About Jauhari

This is me Nurudin Jauhari. Just human like you, I come from Gunungkidul, small place at Yogyakarta, and Today I live at Malang I was born 30/04/1980 in Ponjong, small village in Gunungkidul, Almost my time in 1 - 15 Years stay at this Village. More

This entry was posted in WordPress Code and tagged , , , , .
Bookmark the permalink.

2 Responses to Resize Images using Shortcode with TimThumb

  1. Pingback: How To Integrate Images Shortcode with TimTumb # WordPress Tricks & Tips

  2. Pingback: Nurudin Jauhari

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>