CALL (239) 961-8285
ENDURTECH
  • Web Services
    • Web Design
      • Design and Development
      • Web Consulting and Tutoring
      • Hosting and Maintenance
      • Project Portfolio
    • Media
      • Photo and Audio, Video Editing
      • Social Media Management
      • All Web Related Services
    • Marketing
      • Digital Marketing and Branding
      • Search Engine Optimization
    • Client Portal
      • Remote Web Support
      • Web Services Payment
      • Scheduled Payments
  • Tech Support
    • Services
      • Computer Support and Repair
      • Data Backup and Recovery
      • Computer Security, Virus Removal
      • Computer Networking Support
      • Computer Consulting & Tutoring
      • All Technology Related Services
    • Blockchain
      • Blockchain Technology
      • Cryptocurrency Articles
    • Client Portal
      • Remote PC Support
      • Remote Monitoring & Management
      • Tech Services Payment
  • Articles
  • About
  • Talk to Me
  • Menu Menu

Insert Script into WordPress Body

JavaScript, PHP, Plugins, Snippet, Themes, Web Site Support, WordPress

Recently had a client with a WordPress website in need of injecting a JavaScript tracking code into the beginning part of the Body. This would allow the injected JavaScript tracking code to appear just after the <body> tag of every page on their website. Newer WordPress themes usually provide an option to inject code into the either the header, body or footer areas but the client had a custom WordPress theme with no such feature or ability.

In this article I will show you how to quickly and easily add a script, JavaScript or any other custom code into the Body area of your WordPress website with or without a WordPress plugin.

 

Add Script into WordPress Body

WordPress actions can include “hooks” which are called when that action is encountered by WordPress. For example, when your theme runs header.php, it should cause the function wp_body_open() to run. When the wp_body_open() function is executed you can “hook” into it and provide WordPress with any code that you would want to included.

WordPress themes include a header.php file as a template file. You could simply paste your script, JavaScript code or any other custom tracking codes there but this isn’t ideal. Any such modifications to your (parent) theme files would be lost as soon as you update or change your WordPress theme.

There are better ways of injecting a script or other custom code into the WordPress Body area. The easiest way is with the use of a free WordPress plugin whilst my preferred way is to simply use the built-in WordPress wp_body_open hook. Note, there are other solutions but these two are the best in my opinion.

 

Script Injection WordPress Plugins

There are many plugins available for adding header, body and footer scripts to your WordPress website. Below are two that I would recommend if you are interested in using a WordPress plugin.

  • Header and Footer Scripts plugin by Digital Liberation
  • Insert Headers & Footers + Custom Code Snippets plugin by WPCode
  • Insert Headers & Footers plugin by WPBrigade

 

Adding a Script to WordPress Body

To include a script at the beginning of our BODY tag within our WordPress website we would want to open our child theme’s functions.php file and insert the following example code (excluding the php open and close tags):

The above script simply opens an alert window on your pages, but you may replace the existing script with one of your own. This is basically what the previously mentioned WordPress plugins do just more efficiently. Manually adding the above BODY hook might take a few more minutes to implement but is better in the long run.

 

Adding a Script to Avada Theme Body

To include a script (for example Google Analytics 4 Tag Manager Script) at the beginning of our BODY tag within our WordPress website, using the popular Avada WordPress theme, we would want to open our child theme’s functions.php file and insert the following example code (excluding the php open and close tags):

Conclusion

I welcome your thoughts, questions or suggestions on my article on inserting a script or other custom code into your WordPress Body.

You may support my work by sending me a tip using your Brave browser or by sending me a one time donation using your credit card.

Let me know if you found any errors within my article or if I may further assist you by answering any additional questions you may have.

 

August 6, 2022
Share this entry
  • Share on Facebook
  • Share on X
  • Share on WhatsApp
  • Share on LinkedIn
  • Share on Reddit
  • Share by Mail
https://endurtech.com/wp-content/uploads/2018/04/wordpress-content-management-system.jpg 512 512 Manny https://endurtech.com/wp-content/uploads/2018/04/endurtech-logo.png Manny2022-08-06 18:22:542025-11-12 15:47:35Insert Script into WordPress Body
Search Search

CONNECT WITH US

This field is for validation purposes and should be left unchanged.
Engagement*

Want to say, "thanks"?
Leave me a review on Facebook and/or Google.

You can send me a tip using your Brave browser. Get Brave!

Only used to send you a receipt.
Include a Message
Popular
  • Windows Logo
    Second Monitor on Windows 10 Resets After SleepJuly 2, 2020 - 6:30 am
  • Windows Logo
    How to Disable the F1 Help Key in Windows 10April 15, 2021 - 2:40 pm
  • Cortana Logo
    How to Disable Microsoft’s CortanaApril 6, 2021 - 9:00 am
  • Firefox Logo
    How to Remove All Passwords from Lockwise in FirefoxMarch 26, 2020 - 11:00 am
Recent
  • How to Fix Brother BrLog Errors
    How to Fix Brother BrLog ErrorsAugust 24, 2026 - 10:55 am
  • How to block Facebook crawler
    List of Spider Crawlers to BlockAugust 10, 2026 - 9:20 am
  • Brave Browser Logo
    How to Fix the “Not Secure” Address Bar Err...July 20, 2026 - 12:48 pm
  • Linkpull Extension By Endurtech
    LinkPull Extension, Grab Any File From a URLJuly 7, 2026 - 7:35 pm

STAY IN TOUCH

ENDURTECH Web Design Company Naples, Florida

Endurtech GitHub ProfileEndurtech YouTube ChannelEndurtech LinkedIn ProfileEndurtech Facebook Page

5 Star Google Review for Endurtech - Naples Web Design Company

Learn More & Connect

Search Search
ENDURTECH Logo
Endurtech GitHub ProfileEndurtech YouTube ChannelEndurtech LinkedIn ProfileEndurtech Facebook Page

5 Star Google Review for Endurtech - Naples Web Design Company

Latest Articles

  • How to Fix Brother BrLog Errors
    How to Fix Brother BrLog ErrorsAugust 24, 2026 - 10:55 am
  • How to block Facebook crawler
    List of Spider Crawlers to BlockAugust 10, 2026 - 9:20 am
  • Brave Browser Logo
    How to Fix the “Not Secure” Address Bar ErrorJuly 20, 2026 - 12:48 pm
  • Linkpull Extension By Endurtech
    LinkPull Extension, Grab Any File From a URLJuly 7, 2026 - 7:35 pm

Recent Projects

  • Jewelry Website Gems of Note
    Gems of NoteNovember 15, 2019 - 10:16 pm
  • Gift Store Facebook Business Page Cover Video
    Gift Store Facebook Business Page Cover VideoApril 13, 2019 - 3:58 pm
  • Toledo Yoga BrandBot Footer Integration
    Toledo YogaApril 9, 2019 - 7:26 am
  • Lawyer Association Website with Member Portal
    National Employment Lawyers Association, Florida ChapterFebruary 26, 2019 - 8:00 am

Business Details

Mondays - Fridays
9:00 am - 5:00 pm
Eastern Standard Time
After hours by appointment

SUPPORT PHONE

(239) 961-8285

MAILING ADDRESS

59 Logan Ln.
Lynchburg, VA 24502

Copyright © 2026 ENDURTECH ® All Rights Reserved. Legal
Link to: Google Authenticator versus Microsoft Authenticator Link to: Google Authenticator versus Microsoft Authenticator Google Authenticator versus Microsoft AuthenticatorGoogle Authenticator versus Microsoft Authenticator Link to: Insert Script into WordPress Footer Link to: Insert Script into WordPress Footer WordPress Content Management System IconInsert Script into WordPress Footer
Scroll to top Scroll to top Scroll to top