layers_enqueue_custom_fonts

The Layers layers enqueue custom fonts function.

Description

layers_enqueue_custom_fonts(); 

Usage

  1. if ( !function_exists( 'layers_enqueue_custom_fonts' ) ) { 
  2. require_once '/core/helpers/custom-fonts.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = layers_enqueue_custom_fonts(); 
  7.  

Defined (1)

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

/core/helpers/custom-fonts.php  
  1. function layers_enqueue_custom_fonts() { 
  2. global $layers_custom_fonts; 
  3.  
  4. if( !isset( $layers_custom_fonts ) || ( isset( $layers_custom_fonts ) && empty( $layers_custom_fonts ) ) ) return; 
  5.  
  6. // De-dupe the fonts 
  7. $layers_custom_fonts = array_unique( $layers_custom_fonts ); 
  8. $all_fonts = layers_get_google_fonts(); 
  9.  
  10. // Validate each font and convert to URL format 
  11. foreach ( $layers_custom_fonts as $font ) { 
  12. $font = trim( $font ); 
  13.  
  14. // Verify that the font exists 
  15. if ( array_key_exists( $font, $all_fonts ) ) { 
  16. // Build the family name and variant string (e.g., "Open+Sans:regular, italic, 700") 
  17. $family[] = urlencode( $font . ':' . join( ', ', layers_get_google_font_variants( $font, $all_fonts[ $font ]['variants'] ) ) ); 
  18.  
  19. // Convert from array to string 
  20. if ( empty( $family ) ) { 
  21. return ''; 
  22. } else { 
  23. $request = '//fonts.googleapis.com/css?family=' . implode( '|', $family ); 
  24.  
  25. wp_enqueue_style( 
  26. LAYERS_THEME_SLUG . '-google-fonts',  
  27. $request,  
  28. array(),  
  29. );