Nice asked:”How to prevent admin to be tracked by Google analytics?”

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

* Name, Email, Comment are Required