Skip to content

Instantly share code, notes, and snippets.

@mskian
Last active January 29, 2023 16:34
Show Gist options
  • Save mskian/de5ac2a143c558edad1e7d68be2a423f to your computer and use it in GitHub Desktop.
Save mskian/de5ac2a143c558edad1e7d68be2a423f to your computer and use it in GitHub Desktop.
Umami Wordpress - Add Umami Analytics Code in Wordpress Site - Add this below Code in your Site Specific Plugin or Themes Functions File.
function umami_preconnect_url(){
if(! is_user_logged_in()){
echo '<link rel="preconnect" href="https://umami.example.com" />';
}
}
add_action('wp_head', 'umami_preconnect_url');
function umami_track_code() {
if(! is_user_logged_in()){
?>
<script async defer data-website-id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" src="https://umami.example.com/umami.js"></script>
<?php
}
}
add_action('wp_head', 'umami_track_code');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment