WordPress MU timthumb fix – code snippet

by krike in Code snippets / Freebees on 02 Nov 2010


In one of my latest projects, creating a wordpress premium theme, I need to use the timthumb php class which would properly resize the post thumbnails. It worked perfectly untill I added the theme to the demo which is running wordpress MU (multi user).

The problem is that WordPress MU rewrites the url to the images and therefore timthumb can’t find the images. When I googled for a solution I noticed that I wasn’t the only one having this problem. I tried different solutions but none of them worked so I took a piece of code that was pretty simple and close to the solution and I improved it.

The following function for wordpress should be added in the functions.php of your theme, more instructions can be found in the code snippet itself. If you have any question at all you can always leave a comment below, enjoy! 🙂

[snippet id=43129]

Written by krike

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sit amet nisl nisl. Ut interdum libero vitae quam ultricies et lacinia elit aliquet. Praesent tincidunt, sem tempus feugiat feugiat, turpis tellus scelerisque erat, sit amet feugiat neque arcu ac lectus. Sed at mi et elit interdum scelerisque vitae eu felis.

krike has written 77 posts.

  • ste

    Hi Krike,
    it doesn’t work for me, I’m telling the change I’ve made in the code:
    if(@getimagesize(‘./wp-content/blogs.dir/4/’ . $blog_id . ‘/files/’ . $imageParts[1])):

    $thumbnail = ‘http://’.$_SERVER[‘HTTP_HOST’].’/wp-content/blogs.dir/4/’ . $blog_id . ‘/files/’ . $imageParts[1];

    what’s wronk in your opinion

    • @ste I can’t tell you without having a look at your site, can you give me a link? i’ll be able to help you better.

  • ste

    is www.textilearchitecture.polimi.it/research/