Do you want to connect statistics and analytics so that they do not slow down the site? Let’s take a look at how to add code to the body of WordPress, and why it’s necessary.
It is advised to connect scripts by default in the header of the site, i.e. between the <head> and </head> tags. If this is correct for CSS styles, then not quite for JS. And that’s why.
The site visitor will see the entire content of the page when all connected scripts are executed. If there are a lot of them, then he will have to wait until the content appears. Therefore, it is better to transfer their connection after the page content appears. This means that the scripts will be placed at the end before the closing HTML </body> tag.
How to Insert Code in the WordPress Body
Let’s look at a few ways. Choose the one that is convenient for you.
This is a free WP plugin that does everything by itself.
- Install and activate.
- In the admin panel, open the Settings > Insert Headers and Footers section.
- Add your code to the Scripts in the Body field.
- Click the Save button.
This is a premium solution for optimizing your WordPress resource. One of its features is to insert arbitrary code in the body section.
- Open the Clearfy Pro section.
- Click the Code tab.
- Activate the Code before </body> option and add the script in the box below.
- Save your changes.
Built-in theme tools
Some VI themes have a separate setting for inserting code into the body of the page. It is usually located in one of the sections of the Customizer, which is available under Appearance > Customize.
For example, let’s look at the Reboot theme, in which you can insert arbitrary HTML into different sections of the site.
WP themes are made up of templates. These are separate files that are responsible for different sections of the site. For example, header, footer, sidebar, archive.
If you do not want to install additional plugins, then this method is perfect.
- In your active theme folder, find the footer.php file. It is in every topic.
- Add the script code before the closing </body> tag