Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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