Last active
November 4, 2020 13:27
-
-
Save cobaltapps/3ff5be9f5ffdbe52c0b8b3906c2f4844 to your computer and use it in GitHub Desktop.
The following code allows you to enqueue custom Google Fonts through your Child Theme's functions.php file.
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
add_action( 'wp_enqueue_scripts', 'freelancer_child_enqueue_google_fonts' ); | |
/* | |
* Enqueue custom google fonts. | |
*/ | |
function freelancer_child_enqueue_google_fonts() { | |
/* | |
* Example of the freelancer_google_fonts_url function | |
* with multiple Google Fonts and multiple subsets. | |
* Note that the fonts are required, but subsets are optional | |
* and only necessary if you're using non-default/custom subset | |
* (i.e.. something other than "latin"). | |
* | |
$google_fonts_url = freelancer_google_fonts_url( | |
// An array of Google fonts with their respective styles. | |
array( | |
'Saira Semi Condensed' => '400,700', | |
'Lato' => '400,400i,700,700i', | |
), | |
// An array of Google font subsets associated with the above fonts. | |
array( 'latin-ext', 'vietnamese' ) | |
); | |
/* # Custom Google Fonts | |
* Add Google fonts. | |
*/ | |
wp_enqueue_style( 'freelancer-child-fonts', $google_fonts_url, array(), FREELANCER_CHILD_THEME_VERSION ); | |
} |
There are various ways to do this with general custom fonts, but using @font-face as described in the WPBeginner post below may be worth considering:
https://www.wpbeginner.com/wp-themes/how-to-add-custom-fonts-in-wordpress/
Thanks a loot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice and thanks for sharing this code.
What about custom font that will loaded from host ?
I mean I want to add custom fonts to child them . how should I add them?
Now in my them are working correctly, but I couldn't find way to add all of them to child.