- This topic has 3 replies, 2 voices, and was last updated 4 years, 3 months ago by Leo.
-
AuthorPosts
-
January 6, 2020 at 10:07 am #1123771Victor
Hello,
Happy new year to all the Generatepress team !!!
I am trying to host the Montserrat font locally, I found this topic here ( https://generatepress.com/forums/topic/the-best-way-to-add-google-font-to-gp-child-theme-local-system-font/ ) but I am doing something wrong because its not working.can someone help me?
Here are my steps
1. Dowloaded the subset fonts form Google and uploaded them in the fonts directory in the child theme (generatepress_child/fonts/)
2. Added the below code to generatepress_child/fonts/fonts.css
@font-face {
font-family: ‘Montserrat’;
font-style: normal;
font-weight: 300;
src: url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-300.eot’); /* IE9 Compat Modes */
src: local(‘Montserrat Light’), local(‘Montserrat-Light’),
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-300.eot?#iefix’) format(’embedded-opentype’), /* IE6-IE8 */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-300.woff2’) format(‘woff2’), /* Super Modern Browsers */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-300.woff’) format(‘woff’), /* Modern Browsers */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-300.ttf’) format(‘truetype’), /* Safari, Android, iOS */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-300.svg#Montserrat’) format(‘svg’); /* Legacy iOS */
}
/* montserrat-regular – latin */
@font-face {
font-family: ‘Montserrat’;
font-style: normal;
font-weight: 400;
src: url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-regular.eot’); /* IE9 Compat Modes */
src: local(‘Montserrat Regular’), local(‘Montserrat-Regular’),
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-regular.eot?#iefix’) format(’embedded-opentype’), /* IE6-IE8 */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-regular.woff2’) format(‘woff2’), /* Super Modern Browsers */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-regular.woff’) format(‘woff’), /* Modern Browsers */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-regular.ttf’) format(‘truetype’), /* Safari, Android, iOS */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-regular.svg#Montserrat’) format(‘svg’); /* Legacy iOS */
}
/* montserrat-500 – latin */
@font-face {
font-family: ‘Montserrat’;
font-style: normal;
font-weight: 500;
src: url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-500.eot’); /* IE9 Compat Modes */
src: local(‘Montserrat Medium’), local(‘Montserrat-Medium’),
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-500.eot?#iefix’) format(’embedded-opentype’), /* IE6-IE8 */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-500.woff2’) format(‘woff2’), /* Super Modern Browsers */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-500.woff’) format(‘woff’), /* Modern Browsers */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-500.ttf’) format(‘truetype’), /* Safari, Android, iOS */
url(‘https://app-5de57c44f911c90cdc7baad4.closte.com/wp-content/themes/generatepress_child/fonts/montserrat-v14-latin-500.svg#Montserrat’) format(‘svg’); /* Legacy iOS */
}3.Added to the child theme functions.php the following code:
function gpc_css_stylesheets() {
wp_enqueue_style( ‘gp_font’, get_stylesheet_directory_uri() . ‘/fonts/fonts.css’);
}
add_action(‘wp_enqueue_scripts’,’gpc_css_stylesheets’);add_filter( ‘generate_typography_default_fonts’,’tu_add_system_fonts’ );
function tu_add_system_fonts( $fonts ) {
$fonts[] = ‘Montserrat’;
$fonts[] = ‘Montserrat-Regular’;
$fonts[] = ‘Montserrat-Bold’;
return $fonts;this creates a fatal error, I am guessing that i am doing something wrong on the functions file, here is the complete code I am using:
<?php
/**
* GeneratePress child theme functions and definitions.
*
* Add your custom PHP in this file.
* Only edit this file if you have direct access to it on your server (to fix errors if they happen).
*/function generatepress_child_enqueue_scripts() {
if ( is_rtl() ) {
wp_enqueue_style( ‘generatepress-rtl’, trailingslashit( get_template_directory_uri() ) . ‘rtl.css’ );
}
}
add_action( ‘wp_enqueue_scripts’, ‘generatepress_child_enqueue_scripts’, 100 );add_action( ‘init’, function() {
register_nav_menu( ‘mobile-menu’, __( ‘Mobile Menu’ ) );
} );add_filter( ‘generate_mobile_header_theme_location’, function() {
return ‘mobile-menu’;
} );function gpc_css_stylesheets() {
wp_enqueue_style( ‘gp_font’, get_stylesheet_directory_uri() . ‘/fonts/fonts.css’);
}
add_action(‘wp_enqueue_scripts’,’gpc_css_stylesheets’);add_filter( ‘generate_typography_default_fonts’,’tu_add_system_fonts’ );
function tu_add_system_fonts( $fonts ) {
$fonts[] = ‘Montserrat’;
$fonts[] = ‘Montserrat-Regular’;
$fonts[] = ‘Montserrat-Bold’;
return $fonts;Any idea what I am doing wrong?
Thanks
January 6, 2020 at 3:12 pm #1124010LeoStaffCustomer SupportHi there,
Have you figured this out?
The topic is marked as resolved.
The steps are listed here:
https://docs.generatepress.com/article/adding-local-fonts/Let me know if this helps 🙂
January 6, 2020 at 3:47 pm #1124038VictorAfter many changes I don’t think that I am going to get a noticeable improvement as I am reducing just one http call, so it doesn’t make sense to try to figure how to host local, thank you
January 6, 2020 at 3:56 pm #1124042LeoStaffCustomer SupportNo problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.