
Photo Credit
MS Clarity Exclude Logged In Users
Version: 1.3
Only executes the script for visitors. Prevents script from executing while logged in as Author or above so it will still run for WooCommerce customers.
How to Use
Download > Install > Activate. Use your favorite IDE or just edit within the WordPress plugin editor. Change "xxxxxxxxxx" to be your Clarity ID. Not associated with Microsoft® Clarity®
Example
This prevented me from recording all my logged in back-end work.
Source
This code can be pasted into the functions.php file of your child theme or, download and install the plugin for simple code activation.
<?php
/*
Plugin Name: Lightweight Plugins - MS Clarity Exclude Logged In Users
Plugin URI: https://lightweightplugins.com/plugin/ms-clarity-exclude-logged-in-users
Description: Only executes the script for visitors. Prevents script from executing while logged in as Author or above so it will still run for WooCommerce customers. Not associated with Microsoft® Clarity®
Version: 1.3
Author: WP Maintenance Experts
Author URI: https://wpmaintenanceexperts.com/
License: GPLv2 or later
*/
function lightweight_plugins_clarity_exclude_logged_in(){
if ( ! current_user_can( 'edit_posts' ) ) {
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "xxxxxxxxxx"); // <--- add the site id here
</script>
<?php
}
}
add_action( 'wp_head', 'lightweight_plugins_clarity_exclude_logged_in' );
0 Comments