Get WP-Slimbox2 to Autodetect Additional File Extensions

WordPress Logo

Those of us that use WP-Slimbox2 plugin for WordPress (by Transient Monkey) have the simplest Lightbox/Slimbox integration yet. All we have to do is include an image link in the post, and WP-Slimbox2 does the rest. There is only one problem with it: by default it only autodetects .jpg, .png, and .gif file extensions. This is fine, if those are the only file extensions you use. What if you have some .jpeg or .bmp files referenced? It does not autodetect those extensions. Luckily, there is a fix.

Open slimbox2_autoload.js.php in your favorite code editor. It should be located in wp-content/plugins/wp-slimbox2/javascript folder of your WordPress installation. The following code should be located on line 35.

return /.(jpg|png|gif)(?[dw=&]*)?$/i.test(this.href);

Add the file extensions you would like WP-Slimbox2 to autodetect inside the parenthesis. Make sure you separate the file extensions with a pipe (Shift+backslash key on most QWERTY keyboards), also called a vertical bar. To add .jpeg and .bmp file extensions, your code should look like this:

return /.(jpeg|bmp|jpg|png|gif)(?[dw=&]*)?$/i.test(this.href);

Once you have made the necessary additions, be sure to save the file. WP-Slimbox2 should now autodetect your additional file extensions.

Did this post help you? Be sure to send it to your friends. Did I get something wrong? Please let me know by leaving a comment below. I would love to hear from you.

4 thoughts on “Get WP-Slimbox2 to Autodetect Additional File Extensions”

  1. Hi there,

    desperately trying to understand how to get Slimbox2 to work, maybe I’m overlooking something that’s so obvious to everyone else that no one else is talking about it?

    Installed it in WP, can see the settings page of Slimbox2 and am impressed, but how do I actually use it in a page or post?

    THANKS for any help!!

    Matt

What do you think?