DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

Nice asked some days ago on WpRecipes how can he’ll be able to prevent the blog admin from being tracked as a normal visitor by Google Analytics or any other tracking code. Here’s the answer to Nice question!

To achieve this recipe, we need the current_user_can() WordPress function. This function checks the given parameter, which is the level of the current user, and returns true if the level of the current user is superior or equals to the given parameter.

The following code will track any visitor or blog contributor exept the admin, if he’s logged in, of course.

<?php
if (!current_user_can('level_10')){ ?>
    INSERT ANALYTICS CODE HERE
<?php } ?>

That’s all! Easy, isn’t it? 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *