Created
September 27, 2011 21:48
-
-
Save dalethedeveloper/1246351 to your computer and use it in GitHub Desktop.
Wordpress functions.php snippet to add Google Analytics tracking to wp_nav_menu with Yoast's plugin
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
/* | |
For use in functions.php in combination with: | |
http://wordpress.org/extend/plugins/google-analytics-for-wordpress/ | |
*/ | |
add_filter('wp_nav_menu', 'menu_ga_tracking', 99); | |
function menu_ga_tracking($menu) { | |
if( class_exists('GA_Filter') and yoast_ga_do_tracking() ) { | |
$menu = preg_replace_callback( | |
'/<a (.*?)href=[\'\"](.*?)\/\/([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i', | |
'ga_parse_menu_links', | |
$menu | |
); | |
} | |
return $menu; | |
} | |
function ga_parse_menu_links($matches){ | |
return GA_Filter::ga_parse_link('outbound-menu',$matches); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment