Created
May 26, 2016 16:14
-
-
Save wisecrab/5e27741ac89844af04937087ee34f77c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| /***************************************************************** | |
| *** Phone Link With Anayltics Tracking *** | |
| ** Created By: Chris Steurer | |
| ** Date Added: | |
| ** Contact: info@somedomain.com | |
| ** | |
| ** Create clickable phone links that include a tracking | |
| ** event to register the click in Google Anaytics | |
| *****************************************************************/ | |
| //add [phone_link] shortcode | |
| function shortcode_phone_link($atts, $content=null) { | |
| $phone_link_atts = shortcode_atts( array( | |
| 'number' => '', | |
| ), $atts ); | |
| $phone_number = trim($phone_link_atts['number']); | |
| $remove_characters = array('-', '_', '(', ')', '+', '.', ' '); | |
| $phone_number = str_replace($remove_characters, '', $phone_number); | |
| $phone_link = '<a href="tel:'.$phone_number.'" onClick="ga(\'send\', \'event\', \'Phone Call\', \'Clicked Phone Number\', \''.$phone_number.'\');">'.$phone_link_atts['number'].'</a>'; | |
| return $phone_link; | |
| } | |
| add_shortcode('phone_link', 'shortcode_phone_link'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment