layers_enqueue_custom_fonts
The Layers layers enqueue custom fonts function.
Description
layers_enqueue_custom_fonts();
Usage
if ( !function_exists( 'layers_enqueue_custom_fonts' ) ) { require_once '/core/helpers/custom-fonts.php'; } // NOTICE! Understand what this does before running. $result = layers_enqueue_custom_fonts();
Defined (1)
The function is defined in the following location(s).
- /core/helpers/custom-fonts.php
- function layers_enqueue_custom_fonts() {
- global $layers_custom_fonts;
- if( !isset( $layers_custom_fonts ) || ( isset( $layers_custom_fonts ) && empty( $layers_custom_fonts ) ) ) return;
- // De-dupe the fonts
- $layers_custom_fonts = array_unique( $layers_custom_fonts );
- $all_fonts = layers_get_google_fonts();
- // Validate each font and convert to URL format
- foreach ( $layers_custom_fonts as $font ) {
- $font = trim( $font );
- // Verify that the font exists
- if ( array_key_exists( $font, $all_fonts ) ) {
- // Build the family name and variant string (e.g., "Open+Sans:regular, italic, 700")
- $family[] = urlencode( $font . ':' . join( ', ', layers_get_google_font_variants( $font, $all_fonts[ $font ]['variants'] ) ) );
- }
- }
- // Convert from array to string
- if ( empty( $family ) ) {
- return '';
- } else {
- $request = '//fonts.googleapis.com/css?family=' . implode( '|', $family );
- }
- wp_enqueue_style(
- LAYERS_THEME_SLUG . '-google-fonts',
- $request,
- array(),
- );
- }