First, note that this code use TimThumb to resize pictures. This recipe explain how to install TimThumb on your WordPress blog.
Let's start by creating the shortcode. Just paste the code below into your functions.php file.
function imageresizer( $atts, $content = null ) {
return '<img src="/timthumb/timthumb.php?src='.$content.'&w=590" alt="" />';
}
add_shortcode('img', 'imageresizer');
Then, you can use the following syntax to add an automatically resized image to your blog post:
[img]http://www.yoursite.com/yourimage.jpg[/img]
That's all. Nice, isn't it? By the way, I just published a post on one of my other blogs about Ten WordPress plugins to monetize your blog, you might want to check it out!
Source : http://www.catswhocode.com/blog/10-tricks-to-make-your-wordpress-theme-stand-out - By Alex Denning.
24 Responses
It would be great but i do it manually because i need to look at image size.
If we can setup image resolution + max image site it would be great, but it need to reduce image quality in that scenario.
Tnx
@Peter : yes, that could be done quite easily. Maybe for a future recipe?
I read WordPress will create a feature in WP 2.9 which makes it possible to add a image without having to create custom fields. By doing so you can add the image to your theme instead of having it in your post.
Not entirely related, but I think it is something to look forward to.
Gregorius Tips brother.. this is extra ordinary way of blogging
Nice tip. I love that resizing code, I use it every site.
@Stefan – I will look forward to that as well. I am tired of always having to explain custom fields to clients just for one image! Seems every post will have some main image to feature with the post, about time they make it a standard feature!
I used TimThumb too, but then I discovered WordPress has it’s own build-in functions. Have a look a this:
http://www.maverick.it/en/tech/create-thumbnails-using-wordpress-built-in-functions
How can i show most published author’s list in my blog? Please help!
Thank U.
Very Useful trick..
Can it be possible to add a few more optional parameters like width, height and quality.
It has problem with files named for example “picture-10×10″, where symbols like – and x are.
Rather than a resizer, I’d like to see a cropper tool in WP that would allow us to take a crop slice from an image we put in a blog post. Resizing is nice though and saves time but it’s not enough for control freaks. Like me.
@Valentino, Thanx for the explanation on how to use the already existing wordpress functions to resize an image.
Thanks for the review. I will necessarily try this plug-in.
This is excellent! Thanks for the clear how-to.
One question: How do we handle the alt=”" tag? If I want to set this for each image I include in a post, how can I set this inside of the [img] tag?
Many thanks!
-Jacob
Thanks for the tip. I struggle with resizing images ALL the time. I will most definitely use this. I will say that is one thing that WP seems to be lacking is efficient image handling. Thanks again.
Short and Sweet ! Thanks for the Hack. I shall give it a try.
Hi, I’m using this plugin (wordpress.org/extend/plugins/scissors) and I’m happy with the results
Trackbacks: