gtm4wp_admin_head

The Google Tag Manager for WordPress gtm4wp admin head function.

Description

gtm4wp_admin_head(); 

Usage

  1. if ( !function_exists( 'gtm4wp_admin_head' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-tag-manager-for-wordpress/admin/admin.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = gtm4wp_admin_head(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/admin/admin.php  
  1. function gtm4wp_admin_head() { 
  2. echo ' 
  3. <style type="text/css"> 
  4. .gtmid_validation_error,  
  5. .datalayername_validation_error { 
  6. display: none; 
  7. color: #c00; 
  8. font-weight: bold; 
  9. </style> 
  10. <script type="text/javascript"> 
  11. jQuery(function() { 
  12. jQuery( "#gtm4wp-options\\\\[gtm-code\\\\]" ) 
  13. .bind( "blur", function() { 
  14. var gtmid_regex = /^GTM-[A-Z0-9]+$/; 
  15. var gtmid_list = jQuery( this ).val().split( ", " ); 
  16.  
  17. var gtmid_haserror = false; 
  18. for( var i=0; i<gtmid_list.length; i++ ) { 
  19. gtmid_haserror = gtmid_haserror || !gtmid_regex.test( gtmid_list[ i ] ); 
  20.  
  21. if ( gtmid_haserror ) { 
  22. jQuery( ".gtmid_validation_error" ) 
  23. .show(); 
  24. } else { 
  25. jQuery( ".gtmid_validation_error" ) 
  26. .hide(); 
  27. }); 
  28.  
  29. jQuery( "#gtm4wp-options\\\\[gtm-datalayer-variable-name\\\\]" ) 
  30. .bind( "blur", function() { 
  31. var currentval = jQuery( this ).val(); 
  32.  
  33. jQuery( ".datalayername_validation_error" ) 
  34. .hide(); 
  35.  
  36. if ( currentval != "" ) { 
  37. // I know this is not the exact definition for a variable name but I think other kind of variable names should not be used. 
  38. var gtmvarname_regex = /^[a-zA-Z][a-zA-Z0-9_-]*$/; 
  39. if ( ! gtmvarname_regex.test( currentval ) ) { 
  40. jQuery( ".datalayername_validation_error" ) 
  41. .show(); 
  42. }); 
  43.  
  44. jQuery( ".gtm4wp-dismiss-notice" ) 
  45. .bind( "click", function( e ) { 
  46. e.preventDefault(); 
  47.  
  48. jQuery.post(ajaxurl, { 
  49. action: "gtm4wp_dismiss_notice",  
  50. noticeid: jQuery( this ) 
  51. .attr( "href" ) 
  52. .substring( 1 ) 
  53. }, function ( response ) { 
  54. jQuery( ".gtm4wp-dismiss-notice" ) 
  55. .parent() 
  56. .parent() 
  57. .fadeOut( "slow" ); 
  58. }); 
  59. }); 
  60. }); 
  61. </script>';