Advertisement
Guest User

Untitled

a guest
May 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2. /*****************************************************************
  3.  
  4. *** Phone Link With Anayltics Tracking ***
  5.  
  6. ** Created By: Chris Steurer
  7. ** Date Added:
  8. ** Contact: info@somedomain.com
  9. **
  10. ** Create clickable phone links that include a tracking
  11. ** event to register the click in Google Anaytics
  12.  
  13. *****************************************************************/
  14.  
  15. //add [phone_link] shortcode
  16. function shortcode_phone_link($atts, $content=null) {
  17.  
  18. $phone_link_atts = shortcode_atts( array(
  19. 'number' => '',
  20. ), $atts );
  21.  
  22. $phone_number = trim($phone_link_atts['number']);
  23. $remove_characters = array('-', '_', '(', ')', '+', '.', ' ');
  24. $phone_number = str_replace($remove_characters, '', $phone_number);
  25.  
  26. $phone_link = '<a href="tel:'.$phone_number.'" onClick="ga(\'send\', \'event\', \'Phone Call\', \'Clicked Phone Number\', \''.$phone_number.'\');">'.$phone_link_atts['number'].'</a>';
  27.  
  28. return $phone_link;
  29. }
  30. add_shortcode('phone_link', 'shortcode_phone_link');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement