In this tutorial you are going to learn how to add JavaScript to WordPress which can be a great way to customize your WordPress blog.
Step # 1 – Getting Some Sample JavaScript Code
For this tutorial we are just going to insert a small bit of sample JavaScript. If you want to try this out for yourself there are plenty of sample JavaScripts codes at “http://www.w3schools.com/js/js_examples.asp”. From this site we are going to use the script for an alert box, click on this link and copy the JavaScript code in the frame on the left.
Step # 2 – Inserting the JavaScript Into the Post
Now, navigate to your WordPress blog and make sure you are signed in. From the dashboard, navigate to “Posts” and click “Add New”. Above the post entry area on the right find the tab called “Text” and click this. Paste the JavaScript into the text frame. You can edit the JavaScript code to suit your purpose, or write something that is custom to your needs. Here we will just change the message that appears in the alert box. Finally, give the post a title and click the “Publish” button on the right.
Step # 3 – Testing the JavaScript
Once published click on the “View Post” button at the top of the page. You will be taken to your WordPress blog and you should be able to see your JavaScript code in action. Here we can see that a button has appeared in the post and when we click on this button we see our custom message appear and that is how to add JavaScript to WordPress.