Skip to the page
Docs articles

WordPress

Add the widget to a WordPress site with a code snippets plugin or a small must-use plugin, with no Notert plugin to install, and name your site's signed-in users.

Last updated

View as Markdown
On this page

WordPress needs no plugin of Notert's: the widget is the snippet from your install guide, placed where WordPress puts code on every page. Pick the way that suits your site:

WayBest forSurvives a theme switch
A code snippets pluginMost sites, with no code to writeYes
A must-use pluginDevelopers, and sites that name signed-in usersYes
A child themeA classic theme you already customize in a child themeNo

Before you start

With a code snippets plugin

The simplest way, and it survives theme updates and theme switches. Any plugin that adds code to every page's header or footer works.

  1. In your WordPress dashboard, install and activate a plugin that inserts code into your site's header or footer, if you don't have one already.
  2. Open its settings and paste your snippet into the footer box, which places it before </body>. A header box works too: the widget waits for the page to load either way.
  3. Save, then open a page of your site. The round button appears in the corner once the page has loaded, and within moments the install guide's Check it's live shows your site's address.

With a must-use plugin

A must-use plugin is a single PHP file WordPress loads on every request, with no theme involved and nothing to activate. Create wp-content/mu-plugins/notert-widget.php, making the mu-plugins folder if it doesn't exist, and paste this, with your snippet's workspace id in place of YOUR_WORKSPACE_ID:

<?php
/**
 * Plugin Name: Notert widget
 * Description: Adds the Notert support widget to every page.
 */

add_action( 'wp_footer', function () {
	?>
	<script>
	  window.$notert=window.$notert||[];window.notert=window.notert||new Proxy({},{get:(_,p)=>typeof p=="string"&&p!="then"&&/^[a-z]/i.test(p)?(...a)=>window.$notert.push([p,...a]):void 0});
	  window.notert.init("YOUR_WORKSPACE_ID",{widget:true,theme:"page"});
	</script>
	<script type="module" async src="https://app.notert.io/embed/v1.js"></script>
	<?php
} );

Themes call wp_footer at the end of every page, block themes included, so the widget shows on every page your theme draws. The plugin is listed under Must-Use on the Plugins page, and stays until you delete the file.

Name your site's signed-in users

If people sign in to your WordPress site, as on a membership or course site, the same file can sign a token for each one, so their conversations follow them to every device and your team sees them as verified. First, copy your identity secret under Secrets on MCP & API, and add it to wp-config.php, above the line that says to stop editing:

define( 'NOTERT_IDENTITY_SECRET', 'nis_your_secret' );

Then add this to notert-widget.php, below the code above. It signs the token with PHP alone, so there's nothing to install:

function notert_base64url( $data ) {
	return rtrim( strtr( base64_encode( $data ), '+/', '-_' ), '=' );
}

function notert_token( WP_User $user ) {
	$now    = time();
	$claims = array(
		'sub'            => (string) $user->ID,
		'email'          => $user->user_email,
		'email_verified' => true,
		'iat'            => $now,
		'exp'            => $now + DAY_IN_SECONDS,
	);
	if ( '' !== $user->display_name ) {
		$claims['name'] = $user->display_name;
	}
	$header    = notert_base64url( wp_json_encode( array( 'alg' => 'HS256', 'typ' => 'JWT' ) ) );
	$payload   = notert_base64url( wp_json_encode( $claims ) );
	$signature = notert_base64url( hash_hmac( 'sha256', "$header.$payload", NOTERT_IDENTITY_SECRET, true ) );
	return "$header.$payload.$signature";
}

add_action( 'wp_footer', function () {
	if ( ! is_user_logged_in() || ! defined( 'NOTERT_IDENTITY_SECRET' ) ) {
		return;
	}
	?>
	<script>
	  window.notert.identify(<?php echo wp_json_encode( notert_token( wp_get_current_user() ) ); ?>);
	</script>
	<?php
}, 20 );

The 20 runs it after the snippet, so window.notert exists by then. The token says the user's email is confirmed, so sign only for users whose address your site has confirmed, such as by the email WordPress sends to set a password. What each claim means, and what makes a token fail, is in sign a token on your server.

In a classic child theme

If you'd rather not add a plugin, and your theme is a classic one you customize through a child theme, paste the snippet into the child theme's footer.php, just before </body>. Paste it into the child theme, never the theme itself, so an update to the theme doesn't take it away.

A block theme has no footer.php to edit: use a code snippets plugin or a must-use plugin instead.

If it doesn't appear

  • A performance plugin holds it back. A plugin that combines, defers or delays scripts until the visitor interacts can hold the widget back. Exclude the snippet and https://app.notert.io/embed/v1.js from those settings, often by adding notert to the plugin's list of scripts to leave alone.
  • Cloudflare Rocket Loader. If your site is behind Cloudflare with Rocket Loader on, it can rewrite the snippet's scripts. Add data-cfasync="false" to both of the snippet's <script> tags so Rocket Loader leaves them alone.
  • The console says why. Open the browser's console on a page of your site and look for a line starting Notert:. See troubleshooting.

Start here

Up and down arrowsto moveEnterto openEscto close