Javascript in WordPress posts – Beware!

[tweetmeme]By: Martin Ove

Here’s a quick tip, that might save you the hours of agony, that I’ve just been through.

I tried to use a simple javascript in a post, but it simply didn’t work. I was using the editor in HTML mode of course, but WordPress still managed to sneak up on me and corrupt my code.

The image above shows the problem. To the left is how the editor showed my javascript code. To the right is the source, that I got from the preview window. (right-click and select “view source”)

Notice the paragraph HTML tags – they are enough to make the whole *do nothing*.

Therefore – If you use javascript in a WordPress post, make sure that you have NO WHITESPACES.

That’s it folks. I hope this helps, like this guy helped me.

Leave a Reply

Your email address will not be published. Required fields are marked *