Created
November 8, 2019 17:04
-
-
Save tzkmx/cabd7004cc2256c6240274d02cf0b372 to your computer and use it in GitHub Desktop.
WordPress: Optimize google fonts download to reduce network requests, conditional load to category && page
This file contains hidden or 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 | |
| add_filter('style_loader_src', 'modify_lato_google_font'); | |
| function modify_lato_google_font( $src ) { | |
| $catch= preg_match('/family=Lato/', $src, $matches ); | |
| if($catch) { | |
| $parts = preg_split('/&subset=/', $src); | |
| $src = $parts[0] . '|Oswald:regular,700|EB+Garamond,400'; | |
| //error_log(var_export($src, true), 0); | |
| if(!is_admin() && ( is_home() || in_category(12) )) { | |
| // Font for Colaboradores | |
| $src .= '|Raleway:400,500'; | |
| } | |
| $src .= '&subset=latin'; | |
| } | |
| return $src ; | |
| } | |
| add_action('wp_enqueue_scripts', 'extract_oswald_google_font', 11); | |
| function extract_oswald_google_font() { | |
| wp_dequeue_style('Oswald'); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment