Tagged: google fonts
-
AuthorPosts
-
April 18, 2018 at 3:44 pm #943639
Hello,
I am trying to add some Google Fonts to my Enfold site, but I keep getting a fatal error when I copy this code to the bottom of the functions.php file in my Child theme:
add_filter( ‘avf_google_heading_font’, ‘avia_add_heading_font’);
function avia_add_heading_font($fonts)
{
$fonts[‘Didact Gothic’] = ‘Didact Gothic:400,700’;
$fonts[‘Didact Gothic’] = ‘Didact Gothic:400,700,400italic,700italic’;
return $fonts;
}add_filter( ‘avf_google_content_font’, ‘avia_add_content_font’);
function avia_add_content_font($fonts)
{$fonts[‘Didact Gothic’] = ‘Didact Gothic:400,700,400italic,700italic’;
$fonts[‘Didact Gothic’] = ‘Didact Gothic:400,700’;
return $fonts;
}The error I see, which breaks the site, is:
Fatal error: Cannot redeclare avia_add_heading_font() (previously declared in […]/wp-content/themes/enfold-child/functions.php:9) in […]/wp-content/themes/enfold/functions.php on line 617
Is there some kind of conflict with the parent theme? Thank you!
April 19, 2018 at 1:09 am #943810Hey vcfa_it,
Yes, looking at the error, I believe that avia_add_heading_font function was declared both in functions.php of child and parent theme, to fix this error try changing the first 2 lines of the code you posted above to:
add_filter( 'avf_google_heading_font', 'avia_add_custom_heading_font'); function avia_add_custom_heading_font($fonts)
Hope this helps :)
Best regards,
NikkoApril 19, 2018 at 3:11 pm #944122Hi Nikko,
Thanks for the quick response. I updated the first two lines of code to what you provided above. The site no longer breaks which is great, however I do not see the Didact Gothic font as an available option in the Enfold Child > General Styling > Fonts tab as expected.
How can I get this font to appear?
Thank you!
April 19, 2018 at 3:31 pm #944127Hi!
Please try adding the code as following
add_filter( 'avf_google_heading_font', 'avia_add_custom_heading_font'); function avia_add_custom_heading_font($fonts) { $fonts['Didact Gothic'] = 'Didact Gothic:400,700'; $fonts['Didact Gothic'] = 'Didact Gothic:400,700,400italic,700italic'; return $fonts; } add_filter( 'avf_google_content_font', 'avia_add_content_font'); function avia_add_content_font($fonts) { $fonts['Didact Gothic'] = 'Didact Gothic:400,700,400italic,700italic'; $fonts['Didact Gothic'] = 'Didact Gothic:400,700'; return $fonts; }
Regards,
YigitApril 19, 2018 at 3:35 pm #944130Hi Yigit,
I just added your code exactly to the otherwise empty functions.php file in the Child theme, and unfortunately it breaks the site. Here is the error I get:
Fatal error: Cannot redeclare avia_add_content_font() (previously declared in […]/wp-content/themes/enfold-child/functions.php:17) in […]/wp-content/themes/enfold/functions.php on line 624
April 19, 2018 at 3:54 pm #944139Hi,
Please use following code instead and it should work fine
add_filter( 'avf_google_heading_font', 'avia_add_custom_heading_font'); function avia_add_custom_heading_font($fonts) { $fonts['Didact Gothic'] = 'Didact Gothic:400,700'; $fonts['Didact Gothic'] = 'Didact Gothic:400,700,400italic,700italic'; return $fonts; } add_filter( 'avf_google_content_font', 'avia_add_custom_content_font'); function avia_add_custom_content_font($fonts) { $fonts['Didact Gothic'] = 'Didact Gothic:400,700,400italic,700italic'; $fonts['Didact Gothic'] = 'Didact Gothic:400,700'; return $fonts; }
Regards,
YigitApril 19, 2018 at 4:06 pm #944144The site breaks with that code as well. Here’s the error:
Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) in […]/wp-content/themes/enfold-child/functions.php on line 9
April 19, 2018 at 4:26 pm #944152Hi!
Could you please post FTP and WP admin logins here privately so we can look into it? :)
Best regards,
YigitApril 19, 2018 at 5:38 pm #944205if you add more than one font please do all fonts ( different names ) in one rule together or
rename that functionOn that:
add_filter( 'avf_google_heading_font', 'avia_add_custom_heading_font'); function avia_add_custom_heading_font($fonts) {
after add_filter – the first is the filter name and the second is function name
as long as function names are corresponding – the name could be whatever you like so this will work too.A function needs to be on definition something unique. So if you have allready included another font in line 17 this goes to that error.
And now your are a lucky guy – because on former WordPress Versions this causes a white screen of death.________________
Next Thing: What do you think should happen here – the first line is absolutely superfluous
Same font – same font style
$fonts[‘Didact Gothic’] = ‘Didact Gothic:400,700’; $fonts[‘Didact Gothic’] = ‘Didact Gothic:400,700,400italic,700italic’;
so this might be enough to add:
add_filter( 'avf_google_heading_font', 'avia_add_didact_gothic_heading_font'); function avia_add_didact_gothic_heading_font($fonts) { $fonts['Didact Gothic'] = 'Didact Gothic:400,700,400italic,700italic'; return $fonts; } add_filter( 'avf_google_content_font', 'avia_add_didact_gothic_content_font'); function avia_add_didact_gothic_content_font($fonts) { $fonts['Didact Gothic'] = 'Didact Gothic:400,700,400italic,700italic'; return $fonts; }
you see if functions name are corresponding it will work
The conflict comes from using the function name twiceApril 19, 2018 at 5:47 pm #944208Or whereever (line xy) you have loaded the other font combine those rules to one:
And by the way:
The font added through this code can be found at the bottom of the list ( not sorted in alphabetical order )
add_filter( 'avf_google_heading_font', 'avia_add_heading_font'); function avia_add_heading_font($fonts) { $fonts['Source Sans Pro'] = 'Source Sans Pro:300,300i,400,400i,700,700i'; $fonts['Roboto'] = 'Roboto:300,400,700'; $fonts['Open Sans'] = 'Open Sans:400,400i,600,600i,700,700i'; return $fonts; } add_filter( 'avf_google_content_font', 'avia_add_content_font'); function avia_add_content_font($fonts) { $fonts['Source Sans Pro'] = 'Source Sans Pro:300,300i,400,400i,700,700i'; $fonts['Roboto'] = 'Roboto:300,400,700'; $fonts['Open Sans'] = 'Open Sans:400,400i,600,600i,700,700i'; return $fonts; }
April 20, 2018 at 7:54 am #944477April 25, 2018 at 7:21 pm #946794This reply has been marked as private.April 25, 2018 at 8:34 pm #946849 -
AuthorPosts
- You must be logged in to reply to this topic.