How to Add JavaScript in WordPress Pages or Posts

Looking for a way to add JavaScript code on your website? By default, WordPress doesn't allow you to play around with script-based code. You have access to the backend or use other methods to add the code to your website.


For a simplistic approach, we have provided 3 ways that you can follow to add a JavaScript code on your website. JavaScript is a client-side programming language that doesn't run on the backend or server-side but the browser side. Meaning it requires less bandwidth and doesn't slow down the performance of your website. You can add JavaScript code on any of your website pages and post to change its functionality. The following are the ways that you can follow to add the script code on your website.

Add JavaScript code in the Header or Footer

If you're asked to add a JavaScript code on your website, it is mainly in the Header or Footer section. Mostly third-party website code is added in this area which includes Google Analytics and others.


Job Board WordPress theme

Add JavaScript code manually

You can also add JavaScript code on your website backend manually. For this, you have to go to your Cpanel settings and access the "functions.php" file. All the content and code related to your website are available here. Progress with caution.


If you want to add the code on a specific post or page, search for the required tag or anything in the post and wrap the code in the function section. Now the only thing to remember here is that the "is_single" keyword is used for a post and "is_page" is used for page. Using this way, you can hook your code to both wp_header and wp_footer file. You can also add conditional tags on the specific post or pages as well.

Add JavaScript code inside post or pages via the Plugin

This is the easiest way to add JavaScript code on your WordPress post or Page. There are a lot of plugins available in WordPress that allows you to add script code directly into the custom post.


You don't have to access the backend files or any other thing, just install the plugin and paste the code. Download the plugin and activate it from the dashboard. Now go to the "Screen Options" and check the "Custom Fields" option. Now enter a new custom field in any of the posts/pages and start adding the values.


Remember to CODE prefix them with the required JavaScript code file. Once done, just embed this code anywhere in your page/post text section and you're all set. You can use the Inspect tool to check the live preview of the script code.


We hope that you have learned a lot from this article. Adding JavaScript code in your WordPress site is easy if you follow the mentioned points. If you’re a beginner, we’d recommend you to use the Plugin method. If you have little knowledge of how code works, use the Header/Footer method. The backend file method is suitable for advanced programmers.

Careerfy Job board WordPress theme is designed for Job Portal agencies, its complete Wp job portal theme perfect for career & job recruiters Companies.
Follow
4.7 Star App Store Review!
Cpl.dev***uke
The Communities are great you rarely see anyone get in to an argument :)
king***ing
Love Love LOVE
Download

Select Collections