Jun 2nd, 2007 by admin 4,368 Views
Yesterday I created a new page for this blog: Advertise. This page explains how you can advertise for free on this blog and there are also some paid advertising opportunities. When I started to create this page, I had some serious trouble when I tried to include some Javascript widgets only on that single page. I searched in Google for some Javascript plugins but they were all very complicate to use and most of them did not work for me. I checked codex.wordpress.org to find an easier solution but the only tips I found were these:
To use Javascript inside of posts in WordPress, you need to take a few more steps. Odds are that this usage is for one or only a few instances, so adding the script to the header would be unnecessary.
For the occasional or one time use of Javascript, you need to put the script into a Javascript file and then call it out from within the post. Make sure that each script is defined by its function name such as:
function updatepage(){var m=”Page updated “+document.lastMo…….}
To include a Javascript inside a post, you need to combine both the call to the script file with the call to the Javascript itself.<script type=”text/javascript” src=”/scripts/updatepage.js” mce_src=”/scripts/updatepage.js”></script> <script type=”text/javascript”> <!– updatepage(); //–></script>
If the src attribute of your javascript tag is being stripped out you need to turn off the rich editor (from the dashboard go to Users > Personal Options). If you are using the rich editor the javascript tag’s src attribute may be stripped out even when manually editing in the HTML popup window.
And this should be the easiest way to include Javascript in a single blog post?
Let’s talk about a much easier and more elegant way to execute some Javascript on a single page or inside a single blog post.
Some weeks ago I installed the Google Adsense Deluxe Wordpress Plugin. Thanks to this plugin it is very easy to include Google Adsense blocks inside the template, a single page or even a single blog post.
But isn’t the Google Adsense code Javascript?
Yes it is.
That’s why I had the idea to use the Google Adsense Deluxe Plugin to display Javascript widgets in a single blog post, and it works great. Just have a look at the “Advertise page“. Under “Alexa Rank” you will see an Alexa graph. This is not a simple screenshot but it’s a widget that updates the graph every single day and it’s working perfectly on one single page.
All I had to do is go to the “Options” panel of the Adsense Deluxe plugin, create a new “Adsense Block” and paste the Javascript of my widget inside the “Adsense code” form. I can now add any kind of Javascript widget inside single blog posts by using the same simple technique I used to add the adsense blocks in single blog posts.
This is a great, easy and fast way to add Javascript widgets wherever you want ![]()


subscribed to your feed
Nice to hear that
Google Adsense Deluxe plugin is the easiest to use for your adsense codes withing your post. Do read here about the why Adsense is great for blogs.
[…] you add Adsense blocks inside your blog posts or templates. Recently I wrote an article about how to include and execute Javascript in single posts thanks to Adsense Deluxe. Have a look at this page and scroll down until you see an Alexa Graph. The Alexa Graph is updated […]
Hi - not sure what I’m doing wrong, but I can’t get this to work. I’m running Wordpress 2.21 on my own server, but nothing happens when I try to insert javascript onto a page. I’m new to this. I’m presuming that I should past in the code that’s produced - in this case - into page (using the code tab, not rich editor)?
Thanks in advance for your help.
Hi Rus,
I’m using Wordpress 2.1 and it’s working fine. All you have to do is install the Adsense Deluxe Plugin, go on Options–> Adsense Deluxe Options. Than create “new Adsense Block” and paste the javascript code into ” Adsense Code”. Of course don’t forget to give your new Adsense Block a name. Now, all you have to do is to paste something like this where you want to display the Javascript. Let me know if it works.
I am trying to install a JS code(it is a calculator) on a WP site. Have you ever helped anyone do this? I am using the adsense-deluxe plugin(since adsense is JS code right?) This is a copy of an email I sent to the developer of adsense-deluxe. I don’t know if he can help me or not though-can you?
Support: I think you have a great product but I have a quick question about the application of adsense-deluxe to other javascript code besides adsense. I started a WP blog www.thebestcreditcard4u.com and I wanted to add a JS credit card calculator to my second post. I got adsense-deluxe to display the calculator-all the boxes appear etc. but the Calculate button doesn’t function. You get a msg.(With Internet Explorer) that says error on page:
Line:164
Char:1
Error: Object expected
Code:0
URL: HTTP://www.thebestcreditcard4u.com
Line:125
Char:61
Error: Expected ‘]’
Code:0
URL: etc
I am using WP 2.2.1 The JS code is fine because when I copy and paste it to notepad and save it an HTML file it works in my browser(after allowing ActiveX controls) Is this something that adsense-deluxe can’t do or is there a conflict with WP 2.2.1 and installing JS? I want to install a lot of these scripts on my pages-I think they add a lot of usefullness to your blog. I would gladly make a paypal donation for your script if I could figure out a way to make it work on my WP sites for JS code. Can you help me? I am using your version .8
This sounds really strange. I will search for a solution for this problem and let you know asap.
You’re a genius!
This was what I was looking for. Thank you!
You’re welcome. If you encounter some problems with the Adsense Deluxe plugin, feel free to contact me.
exactly, I tried to add js codes and causing problem with my layout and sidebar widget all over the place
[…] have discovered this method in linkrain.com blog ad decided to expend […]
[…] How to include and execute Javascript in single Wordpress Blog Post I would have never been able to post that Alexa graph into yesterday’s post if I hadn’t have found this article. Quite the way to go about it, but it work. Pasting the javascript directly into the post did not work. (tags: javascript blogging post) […]
very interesting, but I don’t agree with you
Idetrorce
[…] http://www.linkrain.com/articles/how-to-include-and-execute-javascript-in-single-wordpress-blog-post… […]
I’m Bookmark u’r site