How to Add Code to the WordPress Body

How to Add Code to the WordPress Body

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.

Why add scripts to Footer

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.

Also see: How to Remove Duplicate Pages in Tree Comments

How to Insert Code in the WordPress Body

Let’s look at a few ways. Choose the one that is convenient for you.

Insert Headers and Footers

This is a free WP plugin that does everything by itself.

  1. Install and activate.
  2. In the admin panel, open the Settings > Insert Headers and Footers section.
  3. Add your code to the Scripts in the Body field.
  4. Click the Save button.

ClearfyPro

This is a premium solution for optimizing your WordPress resource. One of its features is to insert arbitrary code in the body section.

  1. Open the Clearfy Pro section.
  2. Click the Code tab.
  3. Activate the Code before </body> option and add the script in the box below.
  4. 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.

Also see: How to Remove Duplicate Pages in Tree Comments

Theme template

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.

  1. In your active theme folder, find the footer.php file. It is in every topic.
  2. Add the script code before the closing </body> tag

Leave a comment

Your email address will not be published.