wp_customize_support_script

Prints a script to check whether or not the Customizer is supported, and apply either the no-customize-support or customize-support class to the body.

Description

wp_customize_support_script(); 

This function MUST be called inside the body tag.

Ideally, call this function immediately after the body tag is opened. This prevents a flash of unstyled content.

It is also recommended that you add the no-customize-support class to the body tag by default.


Usage

  1. if ( !function_exists( 'wp_customize_support_script' ) ) { 
  2. require_once ABSPATH . WPINC . '/theme.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_customize_support_script(); 
  7.  

Defined (1)

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

/wp-includes/theme.php  
  1. function wp_customize_support_script() { 
  2. $admin_origin = parse_url( admin_url() ); 
  3. $home_origin = parse_url( home_url() ); 
  4. $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) ); 
  5.  
  6. ?> 
  7. <!--[if lte IE 8]> 
  8. <script type="text/javascript"> 
  9. document.body.className = document.body.className.replace( /(^|\s)(no-)?customize-support(?=\s|$)/, '' ) + ' no-customize-support'; 
  10. </script> 
  11. <![endif]--> 
  12. <!--[if gte IE 9]><!--> 
  13. <script type="text/javascript"> 
  14. (function() { 
  15. var request, b = document.body, c = 'className', cs = 'customize-support', rcs = new RegExp('(^|\\s+)(no-)?'+cs+'(\\s+|$)'); 
  16.  
  17. <?php if ( $cross_domain ) : ?> 
  18. request = (function() { var xhr = new XMLHttpRequest(); return ('withCredentials' in xhr); })(); 
  19. <?php else : ?> 
  20. request = true; 
  21. <?php endif; ?> 
  22.  
  23. b[c] = b[c].replace( rcs, ' ' ); 
  24. // The customizer requires postMessage and CORS (if the site is cross domain) 
  25. b[c] += ( window.postMessage && request ? ' ' : ' no-' ) + cs; 
  26. }()); 
  27. </script> 
  28. <!--<![endif]--> 
  29. <?php