Resize Images using Shortcode with TimThumb

Jauhari

2 comments

Link

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

[php]// Image resize in content
function timmyimg($atts, $content = null) {
extract(shortcode_atts(array(
‘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’);
[/php]

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

[php][img w=540 h=200 class=alignleft alt=My Photo]http://mysite.com/photo.jpg[/img][/php]

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

Share:

Related Post

2 responses to “Resize Images using Shortcode with TimThumb”

  1. RT @jauhari Resize Images using Shortcode with TimThumb http://bit.ly/9XhU9H

  2. […] How To Integrate Images Shortcode with TimTumb August 24th, 2010 By WP Tricks Posted in Tricks Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.Every WordPress Developer has seen that TimTumb is wonderful script, This script is better handle to resize image on the fly and display it what ever size we want and we need. Let’s me show you How To Integrate Images Shortcode with TimTumb. The idea is simple. We will use the power of TimThumb and generated better thumbnail and added in our content using shorcode. We got this tricks from Free WordPress Themes designer. […]

Leave a Comment