Adding JavaScript to a Wordpress Post

T. McSpadden
JavaScript and most blogging platforms are two things that don't always mix.

In the past major social networking communities allowed users to add JavaScript to their blog posts and profiles not realizing that a major security risk was being created. After ending up offline because of these breaks in security sites like Wordpress.com stopped allowing the use of JavaScript on their pages. This has caused a bit of frustration for those who host their blogs for free on the Wordpress site, and for those who use the Wordpress platform on their own server.

While hosting Wordpress on ones own server allows for a lot more flexibility the software's' built in security features still make using JavaScript difficult. Inserting JavaScript directly into a templates sidebar coding can sometimes cause layout problems and errors. Recent upgrades in the Wordpress 2.0 series now allow users using dynamic sidebars to add JavaScript code into text box widgets. This feature makes it possible to add Google Adsense, MyBlogLog, and other JavaScript codes into the sidebars but doesn't help when it comes to adding JavaScript directly into an individual Wordpress post.

Luckily several designers who use Wordpress have developed plugins to help get around this limitation. After trying several with varying results the plugin currently used at my Wordpess powered site, RandomWoman.com is the Inline JavaScript Plugin developed by Volcano at Ooso.net. (site is multi-lingual). The plugin consists of one php file, inline-js.php, which is copied into the wp-contents/plugin directory. After the plugin is placed into the directory and activated it is now possible to insert working JavaScript directly into a post using the following code (after removing excess spacing):

[inline]

< script type= " text/ javascript " >

< the JavaScript you want to insert >

[/inline]

If you would like to add any text after your JavaScript enter a line break code < br > followed by your text. The following is an example:

[inline]

< script type= "text/ javascript ">

< the JavaScript you want to insert >

[/inline]

< br >

The Text You Want To Enter

This code was used in Wordpress version 2.3.2 with the Visual Editor turned off. The editor can be turned on and off by accessing the User Profile in the "Options" folder of the Wordpress dashboard.

Published by T. McSpadden

Tameka McSpadden is a freelance writer currently residing in North Georgia. With both a Bachelor of Science in healthcare management and an associate degree in business administration, T. McSpadden enjoys w...  View profile

8 Comments

Post a Comment
  • Dude2/2/2011

    Doesn't work. All it did was make my page take 3 minutes to load and the javascript was still stripped out.

  • MaMa1/4/2011

    http://mama-tour.blogspot.com/
    Thanks for the post

    Hello.
    Guide
    Attractions

    Tour Pattaya, Pattaya Nightlife
    Pattaya+Nightlife
    Bar, beer, entertainment disco, lady boys show cabaret pubs and live music outdoors at the famous Walking Street is known Nightlife.

  • bram11/8/2010

    help.. what cant i use this plugin correctly..

    im using wordpress 3.0..
    according to http://wordpress.org/extend/plugins/inline-javascript/installation/

    i hav to Disable tag balancing ‘WordPress should correct invalidly nested XHTML automatically’ through the ‘Options / Write’ menu in WordPress..

    but i cant find the 'option / write'

    please anybody would assist me to hav it works on my wordpress 3.0

    thx b4

  • [inline] works for me9/16/2010

    Thanks for pointing out to the right plugin.
    It just plain works.
    I had troubles with '&' sign inside the URLs in JS - WP converted it to , whatever I did.
    That plugin and [inline] [/inline] solved that

  • Cant' get it to work for me4/21/2010

    Unfortuantely, I messed with the plug in and no joy on my end. Thanks for the post though.

  • Dawn2/9/2010

    I'm going to give it a try. I've got a lottery site and have to use iFrame on the page to pull in the lottery results script, which is ok I guess....... until I start to write text below the iFrame script and the iFrame disappears. I wonder why? This is hurting my SEO with Google because I have no content on the page.
    http://www.myarkansaslotterynumbers.com

  • Aitor Serra12/29/2009

    Thanks for this post, It help me a lot.

  • GreatPig3/5/2008

    This is an EXCELLENT plugin.

Displaying Comments

To comment, please sign in to your Yahoo! account, or sign up for a new account.