
Adding JavaScript is the perfect option if you wish to add an array of extra elements to your WordPress website. you can do this without Javascript by installing multiple plugins, but doing this will cause the headache and issues of having to manage them all and also the risk of slowing down your website.
The interesting thing about JavaScript is that it is a coding language that instead of running on your server, within the file manager on your cPanel, it runs on the user’s browser. This allows you to adjust your website without the fear of your website loading times being affected.
WordPress will allow you to add JavaScript it, but it can just be a bit touch-and-go as WordPress does not allow you to add JavaScript code snippet directly into your page. If you attempt to add the code onto the page, there is a good chance WordPress will delete it when you have saved your edits. This will cause confusion and frustration when your site no longer works.
We will be covering in this article the easiest and most effective way you can add JavaScript to your website. But first, we need to cover what a script is.
So, you can understand JavaScript even more than just adding it, it is important to cover what a script even is. A script is a pre-made code language that developers and designers use to perform specific actions.
There are multiple different coding languages for writing scripts all with their own syntax’s, these are the most commonly used languages:
Adding a script using the JavaScript language your website will allow you to add various things to your website, for example:
So, how do you add JavaScript onto your page? There are two easy methods, let's go over them now.
To use this method for adding JavaScript code to your whole website, the best option is to download the Insert Headers and Footers plugin.
You can edit and add JavaScript code to your WordPress theme’s header.php or footer.php files within your file manager via cPanel. However, you must also keep in mind that if you do edit your theme files, every time you update your theme, WordPress will override the code deleting your edits.
Using Insert Headers and Footers plugin is an easy workaround for this problem. Even if you update your theme, your headers and footers code will stay put if you use the plugin.
Once you have added the changes to your header or footer, you will see your changes site-wide, even if you update your WordPress theme, this plugin will save your JavaScript code information, keeping your JavaScript changes active.
If you do not just want your JavaScript to be displayed on your headers and footers, but instead add it to a post or page. You will want to install the Code Embed plugin.
Below you will find the steps for adding JavaScript using Code Embed plugin:



