Created
October 11, 2013 18:46
-
-
Save flowtwo/6939964 to your computer and use it in GitHub Desktop.
This makes sure external links are opened in new window and applies UTM parametres for statistics.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
$.expr[':'].external = function(obj) { | |
return !obj.href.match(/^mailto\:/) && (obj.hostname != location.hostname); | |
}; | |
$('a:external:not(.nonfadelink)').each(function() { | |
$(this).addClass('external').attr("target","_blank"); | |
var url = $(this).attr("href"); | |
$(this).html(function() { | |
var utms = "<?php echo get_bloginfo('name'); ?>"; | |
var utms = utms.split(' ').join('_'); | |
var utmc = "<?php echo get_the_title( $post->ID ); ?>"; | |
var utmc = utmc.split(' ').join('_'); | |
$(this).attr("href", url + "?utm_source=" + utms + "&utm_medium=link&utm_campaign=" + utmc + "").text(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment