live chat on wordpress without a heavy plugin

WordPress chat plugins tend to load a lot on every page, for every visitor, before anyone asks anything. This guide adds Spookat to WordPress with one script tag instead: where to put it in a block theme or a classic theme, how to pass logged-in WooCommerce customers, and what to tell your caching plugin.
what the heavy part usually is
A typical chat plugin for WordPress does three things on every page view: it enqueues its own JavaScript and CSS from your server, it loads the vendor’s widget from their servers, and the widget calls home to register the visit. The first part slows your pages down, and caching plugins then work around it. The last part means every visitor is reported to a third party, whether they chat or not.
Spookat skips all three. The snippet loads one launcher from our CDN, under 4 kb gzipped, with your look inside. It makes 0 requests to our API before a click and sets no cookies. Nothing runs on your server, and nothing is added to your database.
We’ve built a Spookat plugin for the WordPress plugin directory: one click signs the site up and adds the snippet. Until you find it there, any of the methods below does the same job in a minute, and none of them needs a plugin at all.
before you start
Add your site in the Spookat dashboard with your real domain. The install page shows your snippet:
<script src="https://cdn.spookat.com/s/YOUR_SITE_KEY.js" async></script>
The chat connects only from that domain and its subdomains. A staging copy on another domain shows the button, but the chat won’t connect there.
If you’re new to the idea, the pillar guide explains what to look for in any chat widget.
method 1: a block theme (site editor)
Block themes, like the default themes since Twenty Twenty-Two, have a site editor instead of a theme customizer.
- Go to Appearance, Editor, then Patterns (or Template Parts, depending on your version), and open the Footer.
- Add a Custom HTML block at the end of the footer.
- Paste the snippet. Save.
The footer is on every template, so the chat is on every page. WordPress lets only trusted roles save script tags in a Custom HTML block (administrators, on a single site also editors), so do this from an admin account.
method 2: functions.php
This is the clean way for developers, and it’s what our plugin does inside. Add it to your child theme’s functions.php, or to a small site-specific plugin, never to a parent theme that updates will overwrite:
<?php
add_action('wp_enqueue_scripts', function () {
wp_enqueue_script(
'spookat',
'https://cdn.spookat.com/s/YOUR_SITE_KEY.js',
array(),
null,
array('strategy' => 'async', 'in_footer' => true)
);
});
nullas the version keeps WordPress from adding?ver=to the URL.strategy => asyncneeds WordPress 6.3 or newer. On older versions, drop the last argument and passtruefor the footer instead.
Enqueuing also means WordPress knows about the script, so caching plugins and your theme can see it by its handle, spookat.
method 3: a classic theme’s footer
In an old classic theme without a child theme, you’ll find the closing </body> in footer.php. Paste the snippet right above it. It works, but a theme update will remove it. Method 2 in a child theme survives updates.
A “header and footer scripts” type plugin also works, if you already use one. Don’t install one just for this: that’s a plugin to add one line.
page builders
Page builders usually have their own place for site-wide code, often called custom code, custom scripts or footer scripts, in the builder’s or the theme’s settings. Paste the snippet there, set to the footer and all pages. If the builder only offers per-page code, use method 2 instead: one place, every page.
multisite
On a WordPress network, every site with its own domain is its own Spookat site, with its own key, look and channel. A small must-use plugin can pick the key by site:
<?php
add_action('wp_enqueue_scripts', function () {
$keys = array(1 => 'site_live_AAAAAAAAAAAAAAAA', 2 => 'site_live_BBBBBBBBBBBBBBBB');
$key = $keys[get_current_blog_id()] ?? null;
if (!$key) return;
wp_enqueue_script('spookat', "https://cdn.spookat.com/s/$key.js", array(), null, array('strategy' => 'async', 'in_footer' => true));
});
The first site in a Spookat account pays the full price; every other site in the same account that you pay for through Spookat is 30% off.
building sites for clients
A lot of WordPress sites are built by a freelancer or an agency and then handed over. Today you add the client’s site to your own account and pay for it through Spookat: once one of your sites pays full price, every other one is 30% off. A handover, where the client takes the site over as owner and pays us directly while you stay an admin, is coming soon. /partners has both.
setting the look
The look you publish in the Spookat dashboard travels inside the launcher, so there’s nothing else to add. If you’d rather keep it in WordPress, print a window.Spookat before the launcher:
<?php
add_action('wp_head', function () {
$config = array('style' => 'clean', 'accent' => '#2F6FEB', 'side' => 'right');
echo '<script>window.Spookat = ' . wp_json_encode($config) . ';</script>';
});
wp_head prints in the page head, well before the launcher in the footer runs. There are 8 styles; accent is your brand color as hex. The docs list every key.
For a multilingual site (WPML, Polylang), pass the page’s language so the widget matches it: 'lang' => substr(get_locale(), 0, 2). The widget speaks 12 languages and falls back to the visitor’s browser for the rest.
woocommerce: who is writing
On pro and above, you can pass the logged-in customer. Your team then sees logged in as 42 on the Slack card, so “where’s my order” doesn’t start with “what’s your email”. The id is signed with a secret only your server knows, so nobody can pose as another customer.
Make the identity secret on the dashboard’s install page and put it in wp-config.php:
define('SPOOKAT_IDENTITY_SECRET', 'your-secret-from-the-dashboard');
Then sign the current user’s id and pass it:
<?php
add_action('wp_head', function () {
if (!is_user_logged_in()) return;
$id = (string) get_current_user_id();
$user = array('id' => $id, 'sig' => hash_hmac('sha256', $id, SPOOKAT_IDENTITY_SECRET));
echo '<script>window.Spookat = ' . wp_json_encode(array('user' => $user)) . ';</script>';
});
If you set the look in wp_head too, merge both into one window.Spookat array. A missing or wrong signature is not an error; the chat just doesn’t say who it is.
The chat works on shop, product, cart and account pages like on any other page. WooCommerce’s own checkout page is a normal WordPress page, so the chat shows there too, which is where questions about shipping and payment tend to come up.
caching and optimization plugins
Optimization plugins do useful things to your own scripts that can get in the way of a third-party one:
- Combine or minify JavaScript. The launcher is served from our CDN, already small, and it reads its own URL to find the rest of the chat. Exclude
cdn.spookat.comfrom combining. - Delay JavaScript until user interaction. The launcher would appear only after the first scroll or tap. It’s 2 kb and does nothing until clicked, so there’s nothing to gain; exclude it.
- Defer all scripts. Harmless, since the tag is already
async.
After changing the settings, clear the plugin’s cache and check the page again.
cookie banners
Spookat sets no cookies, and before a click it stores nothing in the browser and sends nothing to our API. After a visitor sends a first message, one key in local storage keeps their chat on that device. What that means for your consent banner depends on your country and your other scripts; ask whoever advises you on privacy. The privacy page lists exactly what we keep.
verify it
Open your site in a private window, logged out, with DevTools open:
- Network, “Disable cache”, reload, filter
spookat. One request: the launcher fromcdn.spookat.com, around 2 kb. Two, both fromcdn.spookat.com, if your code sets a style inwindow.Spookatthat isn’t the one you published. Nothing toapi.spookat.com. - Application: no cookies from Spookat, no storage.
- Click the launcher, send a test message, and see it arrive in Slack. The Slack guide covers the connection.
Then log in as a test customer and check that window.Spookat.user is set, if you added it. Type window.Spookat in the console.
Last, look at it on a phone. WordPress themes and WooCommerce like to put things in the bottom corners: a back-to-top arrow, a sticky add-to-cart bar, a cookie settings button. Spookat’s launcher moves up on its own when something fixed or sticky sits in its corner, and back down when it goes. If the launcher sits on top of one of them, move it with side: "left" in the dashboard or in window.Spookat, and check again at 375 px wide.
checklist
- The snippet in the footer (block theme), in
functions.php(child theme), or above</body>(classic theme). Once. - Caching plugin told to leave
cdn.spookat.comalone. - Optional: the look and the logged-in customer in
wp_head, the secret inwp-config.php. - Checked in a private window: one request before a click (two, both from
cdn.spookat.com, if your code sets a style you didn’t publish), no cookies. - Slack connected.
It costs $4.99 a month per site on starter, with unlimited teammates, and the trial is 14 days with no card.