Alternatively, it is advisable to create a backup of your site before implementing any changes. By doing so, you can still get a fully functional version of your website in case any complications arise.
1. Using a Plugin
Here, we will focus on using the “Insert Headers and Footers” plugin.
- Activate the “Insert Headers and Footers” plugin.
- Access your WordPress dashboard.
- Go to Settings and click on “Insert Headers and Footers”.
- In the plugin settings page, locate the “Scripts in Header” box.
- Look for the “Scripts in Footer” box.
- In the end, save the changes.
2. Using a functions.php file
It is recommended to create a child theme to ensure safe updates to the parent theme and to take a backup of your site before proceeding.
To get started, follow these steps-
- Locate and open the functions.php file.
- Copy and paste the provided code snippet into the file.
- If you want the code to apply to a single post, you can modify the code by using the post ID number.
- Save the file once the changes are done.
- You can also repeat this process for a single WordPress page if needed.
Pros and cons of using functions.php file
However, it’s important to note that this approach involves working with code and editing your site’s files. As a result, if you’re not familiar or experienced in coding, it may not be the most suitable option for you. It requires a certain level of technical knowledge and caution to ensure that the modifications are implemented correctly.
- Make a new file in your theme’s directory and give it the name “adding.js”.
- Save the file with the changes.
- Now modify your “header.php” file in the theme’s directory.
<?php %20bloginfo(‘template_directory’); %20?>/custom.js>
Replace the “adding.js” file name with the actual name of your file.
- Now save the changes to the “header.php” file.
- Upload the “header.php” (edited) file to the server.