Sign inBlogSupportContact
Tools

Add custom JavaScript to WordPress without a plugin

A tracking pixel. A chatbot widget. A 5-line analytics snippet. Inject the JS from the admin, named and toggleable. No functions.php, no dedicated header-footer plugin.

4 min read May 2026 create custom script

You need a JavaScript snippet on every page. Not a plugin.

A vendor gave you a 10-line JavaScript widget. An analytics team wants you to add a custom dataLayer push. A marketer wants a chat widget. Each one is just a <script> tag — but each time you install an entire plugin just to paste the code in.

The alternative, wp_head action hooks in functions.php, ties the script to the active theme. Switch themes next year and the script disappears.

What most people do instead

Install Insert Headers and FootersYet another plugin with one giant textarea. No organization, no per-snippet toggle.
Paste into functions.phpTied to the theme. Switch themes — lose every snippet. No organization.
Build a custom mu-pluginRequires SSH/FTP access. Overkill for a chat widget. Hard to toggle without editing code.

A better way: named, toggleable JS snippets

Run create custom script. Name it ("chat widget", "pixel tracker"). Paste the JS. Each snippet outputs as an independent <script> block on every page load. Toggle any snippet off from the Startup Commands page. No theme dependency, no redeploy.

TrueCommander
Custom script registered
Output on every page load
Name: chat widget
Size: 412 characters
Toggle via Startup Commandsactive

The code is output raw inside <script> tags. You're responsible for its correctness. Bad JavaScript can break your frontend. Test locally before registering a snippet site-wide — same caveat as any header-footer plugin.

How it works

Auto-registers as a startup command. On every page load, outputs an independent <script> block. Each registered snippet is separate — delete it from Startup Commands to remove its output. Each snippet has a name, so a dozen of them stay organized.

1
Run command with name + codeGive it a descriptive name. Paste your JS into the -code parameter.
2
Auto-registered as a startup commandEach entry outputs one <script> block. Accumulates — multiple entries = multiple blocks.
3
Toggle or delete from Startup CommandsDisable temporarily without deleting. Delete to remove permanently.
ParameterValue
-nameDisplay name (e.g., "intercom chat", "ga4 dataLayer")
-codeRaw JavaScript. Output verbatim inside <script> tags.
ModelAccumulate — each run adds one independent script block
ScopeFrontend pages only (admin JS unaffected)
Can be used in

Real example

You want Intercom chat on your site. Intercom gives you a 10-line JavaScript snippet. Without this command, you'd paste it into a plugin like Insert Headers and Footers and hope you don't need to change it later.

With this command: run create custom script -name="intercom chat" with the snippet. It's now live on every page. Six months later, your marketing team wants to gate Intercom to logged-in users only. Open Startup Commands, find the "intercom chat" entry, add a condition "user is logged in". Chat only loads for logged-in users, no code changes.

Goes further with TrueCommander

Ready?

Skip the header-footer plugin.

This is one of 91 commands. All included with every license.

Cookies. The short version.

Essential cookies keep the cart and theme working. Analytics only fire if you say yes. Read our policy.