Block Tracking and Detect WordPress Login

I made an update the other day to the detection script I use to block my tracking scripts.

I got tired of forcing ?preview=true onto URL’s when I was searching my own site and I hated the idea of my personal hits from any machine being tracked. It’s real easy for me to login to the WordPress admin and then know my hits aren’t being tracked.

So I modified my is_preview_mode() function from the Block Content and Detect WordPress Preview post and added in one of WordPress’s built-in functions is_user_logged_in().

Here’s the updated function. You just need to replace the old is_preview_mode() function and you’ll be all set!

PHP

<?php
if(!function_exists('is_preview_mode')){
    function is_preview_mode(){
        if(is_user_logged_in()){
            $result = true;
        } else {
            $query = $_SERVER['QUERY_STRING'];
            $pattern = '/(((p=([0-9]*)&)?preview=true)|(p=([0-9]*)))/';
            $result = preg_match($pattern, $query);
        }
        return $result;
    }
}
?>

This site runs on the Thesis WordPress Theme

Thesis Theme thumbnail

If you're someone who doesn't understand a lot of PHP, HTML, or CSS, Thesis will give you a ton of functionality without having to alter any code. For the advanced, Thesis has incredible customization possibilities via extensive hooks and filters. And with so many design options, you can use the template over and over and never have it look like the same site.

If you're more familiar with how websites work, you can use the fantastic Thesis User's Guide and world-class support forums to make more professional customizations than you ever thought possible. The theme is not only highly customizable, but it allows me to build sites with a much more targeted focus on monetization than ever before. You can find out more about Thesis below:

Leave a Comment

Previous post:

Next post: