Created
August 10, 2021 22:40
-
-
Save rogertm/a4fd76b275953352368846e7f68102b7 to your computer and use it in GitHub Desktop.
Agregar Google Fonts a tu sitio WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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