WordPress: Disable Google Analytics in preview

Each time you preview your blog post in WordPress to ensure that everything is in order, your page view goes up in Google Analytics or other analytics service. This messes up your Google Analytics stats by increasing the pageviews. You can easily prevent this with a conditional tag called is_preview(). Wrap your Google Analytics code with this conditions.

<?php 
if( !is_preview()) {
  # Google Analytics Code #
}
?>

You can use the is_preview condition for other purposes a well.

Premium WordPress Themes

Reliable Web Hosting

Smart Web Worker strongly recommends HostGator for your website/blog hosting. Sign up for web hosting at just $3.96/month. Use the coupon code "SMARTBLOGGER25" to get 25% discount on any hosting packages. Get an account with HostGator now!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>