The WordPress way to install Hotjar is clunky
You need heatmaps, recordings, and surveys in one tool. Hotjar delivers, but its WordPress plugin is 50 MB, adds an admin page, and triggers admin-bar notices.
The canonical WordPress paths are: install an analytics plugin (comes with admin pages, updates, subscription nags), paste the snippet into functions.php (breaks when you switch themes), or set up Google Tag Manager as middleware (overkill for one pixel).
What most people do instead
How to add Hotjar to WordPress without a plugin
Hotjar is one tracking script in the head. Output it from a must-use plugin on the wp_head hook:
// wp-content/mu-plugins/hotjar.php
add_action( 'wp_head', function () { ?>
<script>
(function(h,o,t,j,a,r){
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
h._hjSettings={hjid:1234567,hjsv:6};
a=o.getElementsByTagName('head')[0];
r=o.createElement('script');r.async=1;
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
a.appendChild(r);
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
</script>
<?php } ); Set hjid to your Site ID. The same trade-offs as any hand-placed tag:
- Theme-tied in
functions.php(usemu-pluginsto survive theme switches). - The Site ID is hardcoded in the file.
- It records admin sessions and inflates your heatmaps unless you exclude them.
- No consent gating for recordings, a privacy and GDPR concern.
The command handles placement, consent-awareness, and conditions from one line.
A better way: one command, one ID, tracking live
Run enable hotjar with your Site ID. The command auto-registers as a startup command so the tracking snippet outputs on every page load. No theme edit, no plugin, no GTM middleware.
Shown in advanced mode, where commands start with tp. In easy mode you type the same command without the tp prefix.
Consent-aware flag included. Pass -consent_aware=true and the pixel only fires when your cookie-consent plugin's gate has been accepted. Works with any standard WP consent plugin that sets a cookie flag.
How it works
The command hooks wp_head with the Hotjar-provided tracking snippet, then auto-registers itself in Startup Commands so the tracking stays active across requests. Re-running with a different ID updates the existing entry. Disable from Startup Commands to remove.
tp enable hotjar -hid=1234567| Parameter | Value |
|---|---|
-hid (required) | Site ID (format: 1234567) |
-consent_aware | true to only fire after cookie consent (checks standard consent cookie) |
| Scope | Auto-registered as startup command, runs on every frontend page load |
| Where to find the ID | Hotjar dashboard → Sites & Organizations |
| Can be used in |
Real example
Your UX team uses Hotjar. Every WordPress site you manage has a Hotjar install, and every install comes with a plugin you don't otherwise need. Run tp enable hotjar -hid=1234567 and drop the plugin. Heatmaps, recordings, and feedback surveys all still work.
Goes further with TrueCommander
Frequently asked questions
wp_head hook, as shown above, which also avoids the heavy official plugin. The trade-offs are a hardcoded Site ID, no consent gating, and recording that includes admins. TrueCommander does it in one command, consent-aware.hjid in the snippet.