How To Insert JavaScript into WordPress Posts or Pages

What we should know is that the CMS is basically differentiating between design and content. The administrator should be the one that inserts JavaScript so it should come as no surprise to notice that inserting JavaScript through the editor is something that is difficult to do. Thankfully, there are different ways in which you could achieve this. We will highlight those that are the most useful.


Sampled by © JavaScriptBank.com

When you use the WordPress editor the text will be auto-formatted. This automatically restricts inserted script tags. People that want to insert JavaScript code into pages or posts will find this process to be quite frustrating. It also raises some WordPress security problems when it is done wrong.

Disabling Script Tags Filtering In WordPress

Only use this if you do trust your skills. Disabling script tags blocking is something that you can do. You will need to modify the wp-config.php file in order to enable the tags. You just have to define Custom_Tags as being TRUE. Then you want to make the necessary modifications for the functions.php page and you are done.

Remember that this is a method that should never be recommended unless you do know what you do. You are basically going to end up with the security feature being disabled for the entire site and you can add JavaScript at all user permission levels. If there are authors that do not know what to do it is better to simply not enable the option.

Using Plugins That Enable JavaScript Includes


image by wordpress.org

This is basically the simplest option that is available for you right now. You have access to so many useful plugins that will allow the management of JavaScript codes right within posts and pages. There are cases when you have to load JavaScript in the tag of a post or page or after content adjacent to the </body> tag.

In some situations you will want to load the script sitewide while in other cases you just want to focus on a post or a page. You can easily test various different plugins that offer the features you are looking for but the one that is by far the most comprehensive is Scripts n Styles. You would use this WordPress plugin in order to add the scripts you desire at a truly global level, for the entire site, or you can simply add at a post or page level.

By using the WordPress plugin recommended you can include the codes wherever you want to. Everything is simple to do but you still need to at least know exactly what the scripts will do. Since WordPress is made out of different scripts in itself, it is normal for some of the manually added scripts to simply not work well. If you want to use JavaScript codes that would modify some functions of the CMS system, it is better to be sure this is done by a professional. It is a lot more important than what you may think at the moment. You do not want to end up with the blogging platform to not work anymore.


Author

Phong Thai Phong Thai is a Web Developer, Web Coder for 20 years with PHP, JavaScript, CSS. He is the creator of JavaScriptBank.com - provide thousands of free JavaScript code examples, web development tips and tricks, helpful blogging guides.

Follow him on twitter@js_bank or connect with him on facebook@jsbank if you want. His websites for your knowledge: javascriptON.com, inOneSec.com, www.gomymobi.com

Language
Translate this page to English Translate this page to French Translate this page to Vietnamese

Recent articles
How to open a car sharing service
Vue developer as a vital part of every software team
Vue.js developers: hire them, use them and get ahead of the competition
3 Reasons Why Java is so Popular
Migrate to Angular: why and how you should do it
The Possible Working Methods of Python Ideology
JavaScript Research Paper: 6 Writing Tips to Craft a Masterpiece
Learning How to Make Use of New Marketing Trends
5 Important Elements of an E-commerce Website
How To Create A Successful Prototype For Your PCB


Top view articles
Top 10 Beautiful Christmas Countdown Timers
Adding JavaScript to WordPress Effectively with JavaScript Localization feature
65 Free JavaScript Photo Gallery Solutions
16 Free Code Syntax Highlighters by Javascript For Better Programming
Best Free Linux Web Programming Editors
Top 10 Best JavaScript eBooks that Beginners should Learn
Top 50 Most Addictive and Popular Facebook mini games
More 30 Excellent JavaScript/AJAX based Photo Galleries to Boost your Sites
Top 10 Free Web Chat box Plug-ins and Add-ons
The Ultimate JavaScript Tutorial in Web Design


Free JavaScript Tutorials & Articles
at www.JavaScriptBank.com