Skip to content

Instantly share code, notes, and snippets.

@rogertm
Created August 10, 2021 22:40
Show Gist options
  • Save rogertm/a4fd76b275953352368846e7f68102b7 to your computer and use it in GitHub Desktop.
Save rogertm/a4fd76b275953352368846e7f68102b7 to your computer and use it in GitHub Desktop.
Agregar Google Fonts a tu sitio WordPress
<?php
/**
* Enqueue styles
*/
function my_theme_enqueue(){
wp_register_style( 'my-theme-google-fonts', 'https://fonts.googleapis.com/css2?family=Roboto&family=Ubuntu:wght@400;700&display=swap' );
wp_enqueue_style( 'my-theme-google-fonts' );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue' );
/**
* Preload styles
*/
function my_theme_preload_styles( $html, $handle, $href, $media ){
if ( 'my-theme-google-fonts' == $handle ) :
$html = '<link rel="preconnect" href="https://fonts.googleapis.com">';
$html .= '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>';
$html .= '<link href="'. $href .'" rel="stylesheet" media="'. $media .'">';
endif;
return $html;
}
add_filter( 'style_loader_tag', 'my_theme_preload_styles', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment