WP Engine

Solutions
AgencyEnterpriseSmall & Medium BusinessMarketer
How WP Engine supports marketers.Benefits for marketers.Features that help you innovate.
Developer
How WP Engine supports developers.Benefits for developers.Features that help you move faster.
Explore Our Platform
Insights
Thought LeadershipTopics

Read articles, trends, and insights on these topics from leaders in marketing and technology.

Creative AgilityEnterprise PerformanceActionable IntelligenceEcosystem Integration
Resources

Access ebooks, whitepapers, webinars, and other knowledge from our ecosystem of digital experts.
Visit Resource Center.

Delivering a Slam Dunk Experience on WordPressEbook: The Ultimate Guide to WordPress Plugins15 Common WordPress Mistakes Agencies and their Clients Make
Case Studies
About
Our CompanyOur PlatformLatest News

Access the latest news from inside WP Engine.
Visit the Newsroom.

WP Engine Secures Strategic Growth Investment From Silver LakeWP Engine Unveils First WordPress Digital ExperienceWP Engine Expands Global Presence with New Office in Brisbane
Media Center

Get announcements and resources about WP Engine.

Press Releases
Careers at WP Engine
Pricing
Sales Questions?

Contact Sales

Discover why organizations of all types and sizes choose WP Engine — and how it can benefit you.

Chat

1

I'm available right now to answer any of your questions!

Reply

Call

+1-512-201-4819

Contact

Send a message

Compare Plans
Need Support?
Support DocumentationBilling HelpSupport

We offer support 24 hours a day, 7 days a week, 365 days a year. Log in to get expert one-on-one help.

Log in for support

Sales Questions

Contact Sales

Discover why organizations of all types and sizes choose WP Engine — and how it can benefit you.

Chat

1

I'm available right now to answer any of your questions!

Reply

Call

+1-512-201-4819

Contact

Send a message

Sign in
Sign in
Search

Search

Compare Plans
Call Sales +1-512-201-4819
Menu
AgencyEnterpriseSmall & Medium BusinessMarketers
How WP Engine supports marketers.Benefits for marketersFeatures that help you innovate.
Developers
How WP Engine supports developers.Benefits for developers.Features that help you move faster.
Our PlatformPricingResource CenterOur CompanySolution CenterThought LeadershipDocumentationCareers

How to Avoid the “Timthumb” Script

Aaron Brazell 6.13.2011

A lot of themes, especially the magazine layout themes that have become so popular, utilize a script called timthumb. Timthumb exists to dynamically alter the size, and cropping of an image and became popular prior to the WordPress 2.9 addition of “Post thumbnails”.

This script solved a problem when there was no other solution and has significantly aided the advent of new theme concepts over the years.

The problem, though, is that images are static content and should be loaded in a static fashion. If PHP has to be loaded into memory to generate an image, there will be a performance hit that is non-trivial and noticeable when many images are present.

Fortunately, with Post Thumbnails, the need to use timthumb is either eliminated or drastically reduced.

Here’s how to do it.

Inside your wp-admin, open up the Settings menu and click on the Media page. Here, set your image sizes accordingly.

Of course, these are just default sizes. You can also add specialty sizes as well. To do this, add the following to your theme’s functions.php.

[cc lang=”php”]
add_image_size( ‘long-and-wide’, 500, 50, false );
[/cc]

This will create a new image size called ‘long-and-wide’ that is 500 pixels wide, 50 pixels tall and is not cropped. (For more on image sizes, see the WordPress documentation). Of course, you can call your image size anything you want and make it any size you want. This is just an example.

Then, depending on where your theme is invoking the timthumb script, you can replace with code similar to this:

[cc lang=”php”]
if( has_post_thumbnail() )
{
the_post_thumbnail(‘long-and-wide’);
}
[/cc]

This technique uses built in WordPress APIs and reduces the overhead on the servers and page load time and should be used whenever possible.

More WordPress news from WP Engine

Affiliate program now pays EVERY MONTH!Changes to the Curated Plugins List

Comments

  1. yalamber subba says

    April 23, 2012 at 4:05 am

    What about the condition when we need zooming or croping?

    Reply
  2. James Cochrane says

    December 18, 2013 at 8:22 am

    I was searching for a solution for one of the members of Wealthy Affiliate (WA) who was distressed at the fact that hosting at WA did not allow the Tomthumb script and disables it. But the member wanted to know a workaround for it and I found this solution here at WP Engine. It seems like it will fix the situation for him and I have forwarded the post. I found it to be very helpful.

    Best Regards,
    Jim

    Reply
    • Austin Gunter says

      December 18, 2013 at 2:06 pm

      Awesome! That’s great to hear, James. Thanks for the post!

      Reply

Trackbacks

  1. Jason Cosper says:
    August 3, 2011 at 7:30 pm

    […] all of the hubbub around TimThumb, it’s probably a good time to point people to this handy guide on replacing it with functionality that’s already baked into WordPress. This entry was […]

    Reply
  2. Jason Cosper says:
    August 4, 2011 at 8:11 pm

    […] the folks who don’t have the time or the technical knowledge to change over to the Post Thumbnail support built into WordPress, WordThumb (a secure fork & rewrite of […]

    Reply

Leave a Reply Cancel reply

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

  • Subscribe

    Subscribe to our blog to get great tips for your WordPress site.

  • Favorite Tweets by @wpengine
  • Sign In

    Solutions

    • Agency
    • Enterprise
    • SMB
    • Marketer
    • Developer

    Insights

    • Blog
    • Torque
    • Velocitize

    About

    • Our Company
    • Leadership Team
    • Our Platform
    • Careers
    • Affiliates
    • Contact
    • Legal
    • Newsroom
    • Privacy Policy

    Resources

    • Resource Center
    • Documentation
    • Solution Center
    • Find an Agency

    WP Engine

    504 Lavaca Street, Suite 1000
    Austin, TX 78701

    Sales

    +1-512-201-4819
    [email protected]
    7am–7pm CST

    Billing

    [email protected]

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Instagram
    • RSS
    © 2013—2025 WPEngine, Inc. All rights reserved.
    WP ENGINE®, VELOCITIZE®, TORQUE®, EVERCACHE®, and the cog logo service marks are owned by WPEngine, Inc.