Ad blocking plugins can easily cut into any website’s revenue. Not sure if it’s happening to yours? You can use this simple method to find out just how much your traffic is being affected by AdBlockers.

For the purposes of this illustration, I will assume you’ve already set up Google Tag Manager and Google Analytics. If not, go there first, and get it set up. This tutorial also assumes that you are using jQuery.

Set Up an AdBlocker Tracking Variable

Once you’re inside Google Tag Manager, click on the menu item labeled Variables. Under User-Defined Variables, choose New. Under Choose Type, select Custom Javascript. Then configure the script like this:

function () {
  $(document.body).append('<div id="adsense" style="position:absolute; left:-999999px;">Advertisement</div>');
  var eventValue = 'Blocked';
  if ($("#adsense").height()) {
    eventValue = 'Unblocked';
  return eventValue;

Track the Result With a New Tag

Now we have to report this new variable to Google Analytics. Click on the menu item labeled Tags. Set up a new tag like this:

Publish Your Changes

None of this will work until you publish your changes in the Google Tag Manager.

Follow Along in Google Analytics

All you need to do now is watch your Google Analytics in real time as you visit your web site. From Google Analytics, visit Real Time >  Events. Click on Events (last 30 minutes). You will see AdBlockStatus start to appear here. Clicking on AdBlockStatus here will show you how many people are blocking your ads, along with a percentage.

Today I went to import a large number of posts from a live WordPress site to a local copy of the site. We all know that the WordPress Importer tool hasn’t had much love lately and is slightly broken. PHP will time time out you and drive you crazy if you try to use it.

However, there’s WP-CLI to help. Using WP-CLI, you can easily import your XML/WXR files. But when you do this, you may get this error:

Error: This does not appear to be a WXR file, missing/invalid WXR version number

Don’t worry, this is super easy to fix.

  1. Open your exported XML file that you are attempting to import.
  2. Find the line:
  3. Change it to:
  4. Import the file.

Problem solved, at least for me.

Phone numbers have got to be one of the most commonly gathered bits of information in forms. I created a little PHP function that formats them for the most common US strings, 7 or 10 digits.

The Function

function formatPhoneNumber($variableName) {
  global $$variableName;
  // Keep numbers only
  $$variableName = ereg_replace("[^0-9]", "", $$variableName );
  // Remove "1" if it's the first character
  $$variableName = preg_replace("/^1/", "", $$variableName);
  // format for 7 digit numbers
  if(strlen($$variableName) == 7)
    $$variableName = preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $$variableName);
  // format for 10 digit numbers
  if(strlen($$variableName) == 10) // 10 digit numbers
    $$variableName = preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $$variableName);

Calling the Function

if (isset($_POST['phoneNumber'])) {
  $phoneNumber = addslashes($_POST['phoneNumber']);
// Do something with the phone number, i.e. insert into a db...

Things This Doesn’t Account For:

Obviously, this does not perform any form validation. If anything other than a 7 or 10 digit number is submitted, it will only be stripped down to numbers.

Permanently moving one domain to another is a huge task. Creating a single redirect for each page on your site is unrealistic and would suck the very life from your body. Well, relax – there’s an easier way, using htaccess. This will redirect all of your pages to their respective new pages on your new domain. Continue reading

When adding a phone number field to a form, it’s nice to format it (if it isn’t already). This doesn’t replace anything you would do to validate your form via Javascript. But it does create that little extra bit of uniformity, even if it is slightly redundant.

Update: I have updated this a bit and created a reusable function. You can find it hereContinue reading

Working with WordPress and Bootstrap, you might be frustrated with the built in menu options. There isn’t an easy way to tell WordPress to swap out the  current-menu-item class with bootstrap’s active class. Fortunately for you and me, there’s jQuery for that. Just a little dab will do ya.

jQuery(document).ready(function () {

This little blessed bit of jQuery will add the active class to your menu on the fly.

Creating custom functions in your WordPress template’s function.php file is a regular thing for many of us. What you might not know is how easy it is to wrap them in a class, or even why you would. Wrapping them in a class keeps them both organized and self-contained from other functions that may have the same name. This can be especially important if you are using third party plugins. Continue reading

The process of recording music has three steps these days.

  1. Tracking (or more simply put, recording the individual parts of the song),
  2. Mixing (making all of the adjustments, tweeks, and special effects after recording), and
  3. Mastering (Polishing up the final product).

As a producer of my own music, I often run into the temptation to get ahead of myself in these processes. I’ll hear a song I’m writing, and want to start mixing before I’m finished writing it. The next thing I know, I’ll have mastered the thing too. Big mistake! Maybe you’ve done it too. Continue reading