Open In App

How to Add Custom JavaScript Code in WordPress Website ?

Last Updated : 14 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

WordPress is an open-source Content Management System that is based on PHP and MySql and is used to create a dynamic website. It was developed by Matt Mullenweg and Written in PHP. WordPress is one of the most popular that allows customizing and managing the website from its back-end content management system.

WordPress does not allow you to add JavaScript code directly to your WordPress website. For adding the code to your WordPress website you need the plugin to add the custom JavaScript code to your WordPress website. 

In this article, we are going to see how we can add custom JavaScript code to your WordPress website.

 

What is JavaScript?

JavaScript is the most popular scripting language for web pages, it makes the website more dynamic and helps the programmer to add more functionality to your WordPress website.  

It can be used for both client-side as well as server-side development.

Using the JavaScript code you can add many things to your websites, such as a Video player, Calculator, and many more cool widgets.

JavaScript Code snippet:

Javascript




<script type="text/javascript"
   
    // Some JavaScript code
   
</script> 


Adding JavaScript code using the WP Code plugin to the WordPress website: For adding the JavaScript Code to your WordPress website first you have to install the WP Code plugin to your WordPress website.

The plugin helps beginners to the JavaScript code easily to their website and decreases the risk of website breakage.

For adding the code to your WordPress website follow these simple steps.

Step 1: First login to your WordPress website using the user id and password of your WordPress website.

 

Step 2: After login into your WordPress website, Now hover over the “Plugins” section and then click on the “Add New” button to add the “WP Code” plugin to your WordPress website.

 

Step 3: Now search for the “WP Code” in the search box and then click on the “Install Now” button to install the plugin.

 

Step 4: After installing the plugin click on the “Activate” button to activate the plugin.

 

Now the “WP Code” gets appearing in the WordPress website as “Code Snippets” on your WordPress website.

 

Step 5: For adding the code to your website, Now click on the “Code Snippets” and then click on “+Add Snippet” to add the JavaScript code to your WordPress website.

 

Step 6: Now the WP Code window appears on your screen, Click on the  Your Custom Code” to add the custom code to your WordPress website.

 

Step 7: After choosing the  Your Custom Code”. Now choose the “JavaScript Snippet” in code the type to add the custom code to your WordPress website.

 

Step 8: Now after adding the JavaScript custom code to your website, then click on the “Save Snippet” button to save the custom code to your WordPress website. We use simple JavaScript Code.

console.log('Hello World');
alert("Hello GFG");

 

After saving the code snippet also activate the using the “Activate” toggle.

 

Step 9: Finally click on the “Update” button to save the code snippet and it will start working on your WordPress website.

 

This is how you can add custom JavaScript code to your WordPress website. 

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads