Site logo

Archived topic

Trouble adding custom font

6 replies · Started by Pamela on March 28, 2021

Viewing posts 1–7 of 7

I would like to add Ananda Black to my site as the client uses it for her wordmark. I'm using paid GeneratePress, paid GenerateBlocks, and Mike Oliver's "Coach" demo site. I don't believe I am using any caching.

Here's what I've done:
1. Uploaded the eot, svg, and woff files to the generatepress_child theme folder.
2. Added this code to my functions.php of the child theme.

add_filter( 'generate_typography_default_fonts', function( $fonts ) {
$fonts[] = 'Ananda-Black';

return $fonts;
} );

3. Added this to the style.css of the child theme:

@font-face {
font-family: 'Ananda-Black';
src:url('Ananda-Black.ttf.woff') format('woff'),
url('Ananda-Black.ttf.svg#Ananda-Black') format('svg'),
url('Ananda-Black.ttf.eot'),
url('Ananda-Black.ttf.eot?#iefix') format('embedded-opentype');
font-weight: normal;
font-style: normal;
}

4. Deactivated all my plugins except for GP, GB, and WPShowPostsPro.

I'm fairly sure the font files uploaded correctly, as if I manually add css for H1 to the customizer css, the font displays correctly. How can I make it show up in the fonts list in the customizer?

Just in case I wrecked functions.php, I'll paste all of it below.
--------------

<?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_filter( 'generate_typography_default_fonts', function( $fonts ) {
$fonts[] = 'Ananda-Black';

return $fonts;
} );

It suddenly appears to be working with no additional action on my part.

EXCEPT...
I still can't see the font in my GenerateBlocks blocks while I'm designing the page. It looks good in the browser after the page is published. But not while I'm working on it.

What am I doing wrong?

I'll attach a photo of what I see in the editor vs the published browser.

`I've now added

add_action( 'enqueue_block_editor_assets', function() {
wp_enqueue_style( 'godmother', 'https://godmotherofcanadiancountrymusic.com/public_html/wp-content/themes/generatepress_child/style.css' );
} );

to the functions.php of my child theme, but it doesn't seem to have made the font show up in my GB blocks. The code in style.css is in my original post. (I do not have smart quotes in the PHP)

There seems to be an issue w/ the URL you've added. There's a public_html/

Instead of:

https://godmotherofcanadiancountrymusic.com/public_html/wp-content/themes/generatepress_child/style.css&#8217

Try:
https://godmotherofcanadiancountrymusic.com/wp-content/themes/generatepress_child/style.css

Heyyyyyy.... that was it! Thank you again, Elvin. You always figure it out.

No problem. Glad you got it sorted. :D

This archived topic is closed to new replies.