Sunday, December 14, 2008

JavaScript Logic: WordPress Plugin

One of my biggest gripes about many plugins (and even some themes) is how JavaScript is handled. Many times, it’s loaded on every page of your site without the need for it.

There’s also potential conflicts between different JavaScript libraries and other scripts. It can be problematic having many different scripts loading at once.

This plugin allows you to conditionally load JavaScript files. I stole the idea from Widget Logic (which is an awesome plugin).
How to use this plugin

I’ve included a full readme.html, so I wouldn’t have to add too many instructions to this post. To conditionally include JavaScript, you need to understand how WordPress conditional tags work. There is no other way around that.

You can load many of the scripts packaged with WordPress, those included with the plugin, or an external JavaScript file.

Here’s what the plugin settings page will look like (click image for larger view):

WordPress Plugin: JavaScript Logic Settings
Some things to note about this plugin

This is an early beta release, so it’s not fully developed. There’s the likelihood of a bug here or there. All files selected in each JavaScript set will be uploaded (choosing one won’t overwrite the others).

The settings page will also be located under Appearance > JavaScript Logic. I done this because my next plugin will be Stylesheet Logic to compliment this plugin. Plus, I’m usually tinkering with theme settings more than anything.

If you want to see it in action, notice that I’m conditionally including thickbox with has_tag('gallery') on the single view of posts with the Gallery tag.

If you have ideas, I’m certainly open to hearing them.

Source:

No comments: