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
im still having a problem
if i put my adsense javascript on post
the browser doesnt stops loading it seems it hangs already.
so i tried installing adsense insertion plugin
and also cannot save my adsense code
and search for javascript and landed on this page
but stil after activating your plugin
my javascript saving still does not complete
hope someone could help me.
thanks
using wp2.7.1
Hi Yaap,
OK, I’ll look into that one.
Andy
Thank you so much! I was loosing my mind with the most simple Javascript that was not working inside of Wordpress. I had no idea that WP somehow blocked Javascripts from executing without your plugin. What a relief – thanks!
Big Thanks to u…………….
My head ache gone b’cos of ur plugin.
It’s awesome.
Hi Guys,
Installed the plugin but having a problem, it doesn’t render the javascript! Its a very simple script, and it appears in the code but not on the page.
Any ideas? Here’s the link to the page:
http://www.review-hostel.com/index.php/book-a-trip/
Thanks for any help!
Hi,
There are a couple of parameters at the end of the SRC for that code:
pid=3476707&aid=10524311
I’m guessing that should be
pid=3476707&id=10524311
I’ll see what I can find out.
Andy
Thanks a bunch, this has been the thorn in my side until i found this website. Works perfect.
Thanks a lot for your plug-in.
MC
http://www.lobbycratie.fr/2009/07/27/energie-nucleaire-premiere-partie-les-nucleocrates/
Thanks for the plug-in.
One thing though, when unzipped directly to site folder (linux), extracted folder name contains space… would be nice if extracted name is like ‘wp_ayb-javascript-in-posts’…
Hi CoffeeHarmony,
No worries. Great idea on the folder name. I’ll rectify that in the next release.
Andy
Thank you! I was looking for this for a while…
Work link a charm!. Thank you.
Great plugin! Thanks a lot. Worked perfectly and now I can easily embed popshops store without the WP affiliate store plugin.
Thanks..works like a charm.
I had trouble getting ebay sniplet to show on wordpress before. thanks again. Here is my site http://eye-shadows.info
Gracie mile!
Funciona a la primera.
good post i as know. Many JavaScript implementations do not warn against and questionable coding practices. Yes, that’s nice for the site that “works best with Internet Explorer” (designed with templates, scripted with snippets copied from forums).so But it’s a nightmare when you actually want to write quality, maintainable code