Announcement List
Subscribe to receive subscriber-only discounts, bonuses, and private content.
 
Your Name:

 
Your E-Mail:

 
Recent Comments

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

IMPORTANT UPDATE ON 02 December 2009: JS seems to be enabled in recent WP releases. Can you take a look at this post and let me know what you discover?


OK. Enough. I’ve had it. How can WordPress not allow built-in Javascript in your post content. And more importantly, how come no-one has released a simple plugin to allow it?

Well, someone has.

Me.

Today.

It took about 5 minutes to write, after 2 hours of messing around with various alternative plugins, trying to hack them to work.

Download The Plugin
Click here to download the plugin.

Installation Instructions
1. Download the plugin
2. Unzip it
3. Copy the one file contained therein to your wp-content/plugins directory
4. Log into WordPress. Go to Plugins. Enable the plugin
5. Insert the javascript in your post.

Upgrade Instructions
1. Download the plugin
2. Unzip it
3. Copy the one file contained therein to your wp-content/plugins directory

That’s it.

WordPress Version Compatability
WP 2.7 – Version 1.0, 1.1 of the plugin works OK
WP 2.3.3 – Version 1.0, 1.1 of the plugin works OK
WP 2.3.2 – Version 1.0, 1.1 of the plugin works OK
WP 2.0.3 – Wordpress.com don’t keep a copy of this archive, so I can’t test this version.

Comments
I’m using the simple text editor in my posts, by disabling the WYSIWYG editor in my Wordpress profile. (See Users->Your Profile – uncheck the box marked ‘Use the visual editor when writing’)

I’ve not tried it with the visual editor, as I never use it anyway.

Update (18th July 2007): The WYSYWIG editor definitely breaks it when you edit the post (It puts a backslash in front of any single-quotes). You can go into the “code” view and fix it manually, but you have to do that each time you edit the post.

Update (20th July 2007) : I’ve just tested the plugin with two inline javascript calls, and one call to an external script and it worked fine. Just one note: any JS called in the post will ALSO take effect when you edit the post, since it will run in the preview section.

Update (3rd January 2008): I’ve started the “WP version compatability” list above. Feel free to let me know if you have another version, and the plugin works or doesn’t. I’ll do my best to keep this list up to date.

Update (03 February 2009): Just release version 1.1, which fixed some issues with Javascript code formatted in multi-line statements. No idea how I missed this one, but thanks to the people who do actually add their sample JavaScript code to the comments on this post!

Example

78 Responses to “Javascript In WordPress Posts”

Leave a Reply