Last Updated: August 30, 2014

3 Ways to Add JavaScript to WordPress Posts or Pages

You might have modified your WordPress theme to add a JavaScript code but there are times when you may want to add JavaScript to a specific post or page. So, In this post I will explain you how to add JavaScript code to single WordPress post or page.

  • If you are running a self hosted WordPress blog than you can simple add the JavaScript code to your post through the built-in editor, just switch to HTML mode and paste the code.

Adding JavaScript in WordPress Posts and Pages

  • Alternatively, you can install a WordPress Plugin “Allow Javascript in Posts and Pages” which enables you to add JavaScript to blog posts and pages just by adding a simple short-code.
  • And if you don’t want to install an extra plugin to your WordPress Blog you can simply add a Custom Field (js) and paste the JavaScript code into the Value field. After that just add short-code in your post – [cf]js[/cf].

Adding JavaScript in WordPress using Custom Fields

Adding JavaScript in WordPress posts using Custom Fields

Also See: How to add PHP Code in WordPress Widget

3 Comments

  1. Stalyn says:

    thanks!

  2. Really needed post Brother,Thanks a lot for sharing.need more post related to WordPress dashboard Brother.Really great work once again thanks a lot for sharing.

  3. Ravi says:

    HI Rajan,

    Thank you very much for your post.
    I have query regarding your post, I am added custom meta box in theme and the name is custom box is js when I add the [cf]js[/cf] or [js]js[/js] it have not display my script.

    Could you please help me.
    Thank you,
    Ravi Pratap

Leave a Reply

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

*