Correcting ThickBox Path in WordPress

For some of my larger images, I usually show a thumbnail in the post, and then allow the visitor to enlarge the image by clicking on the thumbnail. While there are many ways of doing this, I simply used WordPress’ built in ThickBox code to display a larger popup image of the thumbnail. After using ThickBox, I quickly ran into a slight problem – the path to the files wasn’t correct so some of the images weren’t be displayed.

In order to correct the problem, I manually edited the ThickBox Javascript file to point to the correct location, however, each time I updated WordPress to a newer version, the file would be overwritten. This caused me to once again go into the Javascript file and edit the file. I managed to find a better solution on the WordPress forums, which I explain below.

A Better Solution

As mentioned above, I ran into a file path problem when using ThickBox. The location in the Javascript file wasn’t pointing to the correct location for the ThickBox images. This prevented the close button from displaying properly within the ThickBox window.

While doing a search in Google, I came across the ‘Thickbox “Close” not showing’ thread in the WordPress forums. Apparently this isn’t a problem that only I have experienced.

One of the moderators on the forum posted a function that can be added the functions.php file in the WordPress template that will automatically correct the ThickBox path value. Figuring it was an easy fix, I added the code to the file and reset the value in the Javascript file. The code I added was:

// Correct image path issue in thickbox
function load_tb_fix() {
  echo "\n" . '<script type="text/javascript">tb_pathToImage = "' . get_option('siteurl') . '/wp-includes/js/thickbox/loadingAnimation.gif";tb_closeImage = "' . get_option('siteurl') . '/wp-includes/js/thickbox/tb-close.png";</script>'. "\n";
}
add_action('wp_footer', 'load_tb_fix');

I opened a post that used ThickBox to display larger versions of an image. It was a nice surprise when I noticed that the close image appeared on the ThickBox window. The above function worked perfectly. I tried the same code on another WordPress blog, and it worked on that one too.

If you are experiencing problems with the path value that is set in the ThickBox Javascript file, then try using the above function to automatically correct it for your blog. The nice part is, if the code didn’t work, I could have as easily deleted the function from the functions.php file.



WordPress Bible (Paperback)

By (author) Aaron Brazell

List Price:$49.99 USD
New From:$7.00 In Stock
Used from:$2.95 In Stock

buyamzon button Correcting ThickBox Path in Wordpress

You may also like:

Wordpress Logo

New WordPress Theme – Slow Performance

Wordpress Logo

WordPress Error: Allowed Memory Size

Wordpress Logo

WordPress: Cannot Modify Header Information

Wordpress Logo

How to Prevent Scripts from Loading for Logged in Users in WordPress

4 people had something to say about “Correcting ThickBox Path in WordPress”:

Comments


  1. Great tip, Paul! I knew about the Thickbox option, but wondered why the proper “X” never appeared.
    Twitter:


  2. perfect Paul! that´s it. you make my day :-)

    regards

    tabs


  3. Hm.. This is nice. Thanks!
    Andrew Walker recently posted…Five Great Cities to watch hockeyMy Profile

Do you have something to say? Let everyone know!

Commenting policy: All comments are moderated for spam. You must use your real name and not your website name or keywords. If a comment is deemed to be spam, then it will be deleted or edited. Links to your website within the comment body is not permitted, but you are free to use CommentLuv to add a link to your latest post. If you wish to add a link to your website, you can always contact me about submitting a guest post.






CommentLuv badge
This blog uses premium CommentLuv which allows you to put your keywords with your name if you have had 5 approved comments. Use your real name and then @ your keywords (maximum of 3)

Previous Post:

Next Post: