salmancreation

Google Fonts - Enqueue Font for WP Theme

Apr 2nd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. function theme_slug_fonts_url() {
  2. $fonts_url = '';
  3.  
  4. /* Translators: If there are characters in your language that are not
  5. * supported by Lora, translate this to 'off'. Do not translate
  6. * into your own language.
  7. */
  8. $lora = _x( 'on', 'Lora font: on or off', 'theme-slug' );
  9.  
  10. /* Translators: If there are characters in your language that are not
  11. * supported by Open Sans, translate this to 'off'. Do not translate
  12. * into your own language.
  13. */
  14. $open_sans = _x( 'on', 'Open Sans font: on or off', 'theme-slug' );
  15.  
  16. if ( 'off' !== $lora || 'off' !== $open_sans ) {
  17. $font_families = array();
  18.  
  19. if ( 'off' !== $lora ) {
  20. $font_families[] = 'Lora:400,700,400italic';
  21. }
  22.  
  23. if ( 'off' !== $open_sans ) {
  24. $font_families[] = 'Open Sans:700italic,400,800,600';
  25. }
  26.  
  27. $query_args = array(
  28. 'family' => urlencode( implode( '|', $font_families ) ),
  29. 'subset' => urlencode( 'latin,latin-ext' ),
  30. );
  31.  
  32. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  33. }
  34.  
  35. return esc_url_raw( $fonts_url );
  36. }
  37.  
  38. ====================== two method =======================
  39.  
  40.  
  41.  
  42. function google_fonts() {
  43.     $query_args = array(
  44.         'family' => 'Open+Sans:300,800|Philosopher:400,700',
  45.         'subset' => 'latin,latin-ext'
  46.     );
  47.     wp_enqueue_style( 'google_fonts', add_query_arg( $query_args, "//fonts.googleapis.com/css" ), array(), null );
  48. }
  49. add_action('wp_enqueue_scripts', 'google_fonts');
Add Comment
Please, Sign In to add comment