Advertisement
arie_cristianD

auto load custom fonts

Mar 25th, 2024
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. /*  auto laod custom fonts */
  2.  
  3. add_action(
  4.     'jeg_before_inline_dynamic_css',
  5.     function () {
  6.         $custom_fonts = get_theme_mod( 'jnews_additional_font', array() );
  7.         if ( ! empty( $custom_fonts ) ) {
  8.             $additional_fonts   = '';
  9.             foreach ( $custom_fonts as $font ) {
  10.                 $custom_variant = $font['font_weight'] . $font['font_style'];
  11.                 /* if selected font variant empty load all varint of custom font*/
  12.                 $font_src = array();
  13.                 if ( ! empty( $font['eot'] ) ) {
  14.                     $font_src[] = "url('" . wp_get_attachment_url( $font['eot'] ) . "#iefix') format('embedded-opentype')";
  15.                 }
  16.  
  17.                 if ( ! empty( $font['woff'] ) ) {
  18.                     $font_src[] = "url('" . wp_get_attachment_url( $font['woff'] ) . "') format('woff')";
  19.                 }
  20.  
  21.                 if ( ! empty( $font['ttf'] ) ) {
  22.                     $font_src[] = "url('" . wp_get_attachment_url( $font['ttf'] ) . "') format('truetype')";
  23.                 }
  24.  
  25.                 if ( ! empty( $font['eot'] ) ) {
  26.                     $font_src[] = "url('" . wp_get_attachment_url( $font['svg'] ) . "') format('svg')";
  27.                 }
  28.  
  29.                 $src          = 'src: ' . implode( ',', $font_src ) . ' ;';
  30.                 $variants_src = " @font-face { font-family: '" . $font['font_name'] . "'; " . $src . " font-weight: {$font['font_weight']}; font-style: {$font['font_style']}; } ";
  31.  
  32.                 $additional_fonts .= $variants_src;
  33.             }
  34.             echo '<style id="additional_fots" type="text/css" data-type="additional_fots">' . $additional_fonts . '</style>';
  35.  
  36.         }
  37.     }
  38. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement