Umami Analytics
Adds the privacy-friendly Umami analytics script (cloud or self-hosted) to every public page, skipping logged-in staff.
Opens WPIDE on
Code
add_action( 'wp_head', function () {
$website_id = 'YOUR-WEBSITE-ID'; // Umami website ID.
$script_url = 'https://cloud.umami.is/script.js'; // Your script URL if self-hosted.
if ( 'YOUR-WEBSITE-ID' === $website_id || current_user_can( 'edit_posts' ) ) {
return;
}
printf( "<script defer src=\"%s\" data-website-id=\"%s\"></script>\n", esc_url( $script_url ), esc_attr( $website_id ) );
} );
Notes
Replace YOUR-WEBSITE-ID with your Umami website ID (and $script_url if self-hosted); nothing is output while the placeholder is in place.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.