Install guides / WordPress

Add a support chat widget to WordPress

The Product.tech chat answers your visitors from your help center, hands the questions it can't answer to your team, and shows what's new. Here's where its line goes on WordPress.

Before you start

Copy your own line from your dashboard, on the Chat widget page. The examples here use acme-invoices, our demo product, so swap in yours. The button stays hidden until you publish an article, so it's safe to add the line first.

Add it to WordPress

The simplest way, with no theme files to edit:

  1. In your WordPress admin, go to Plugins, then Add New, and install and activate WPCode (Insert Headers and Footers).
  2. Go to Code Snippets, then Header & Footer.
  3. Paste your line into the Footer box and save.

Or, if you keep a child theme or a small plugin of your own, add it with the wp_footer hook, which prints it just before </body> on every page:

functions.php

add_action('wp_footer', function () {
    echo '<script src="https://product.tech/widget.js" data-product="acme-invoices" async></script>';
});

Good to know

  • Avoid pasting it into your theme's own footer.php: the next theme update replaces that file and the line with it.
  • A caching or speed plugin that delays or combines JavaScript can hold the chat back. If the button doesn't appear, exclude product.tech/widget.js in its settings and clear its cache.
  • On WordPress.com, installing plugins needs a plan that allows them.
  • If you list the sites allowed to show your chat, on the Chat widget page, add every address this site is served from, staging addresses included. With no list, any site can show it.

Check that it works

Open your site in a private window, signed out. The button appears in the bottom corner after a moment.

No button? Open the browser's console. A message starting with [product.tech] says what's wrong, such as a missing data-product or a site that isn't on your list of allowed sites. With nothing there, check that your help center has at least one published article.

Tell the chat who is signed in

When someone is signed in to your product, the chat can show their email address on the conversation in your inbox, so you can write back, and answer them from your private articles. A page can claim to be anyone, so the address comes with a signature your server makes with a key only you hold.

Create a key in your dashboard, under Customer access, then Your site's sign-in. Keep it on your server as PRODUCTTECH_WIDGET_KEY, never in code that reaches the browser.

If people sign in to your WordPress site, add the key to wp-config.php as define('PRODUCTTECH_WIDGET_KEY', '…');, then tell the chat who they are:

functions.php

add_action('wp_footer', function () {
    $user = wp_get_current_user();
    if ($user->exists()) {
        $visitor = [
            'email' => $user->user_email,
            'name' => $user->display_name,
            'hash' => hash_hmac('sha256', strtolower($user->user_email), PRODUCTTECH_WIDGET_KEY),
        ];
        echo '<script>window.ProductTechUser = ' . wp_json_encode($visitor) . ';</script>';
    }
    echo '<script src="https://product.tech/widget.js" data-product="acme-invoices" async></script>';
});

Options

Add any of these to the line, next to data-product. Each one wins over what you picked on the Chat widget page.

data-position="left"
The corner for the button and the chat: left or right.
data-color="#0a7d5a"
The button's colour, as a hex value.
data-label="Need help?"
The button's words.
data-theme="dark"
Light, dark or system, which follows each visitor's device.

To open the chat from a link or button of your own, call ProductTechWidget.open().

Other platforms

New to Product.tech? It writes your help center from your live app, and from your code once you connect GitHub, then drafts release notes from merged pull requests. See how it works.

Add a support chat widget to WordPress · Product.tech