Tagged: 

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #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!

    #943810

    Hey 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,
    Nikko

    #944122

    Hi 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!

    #944127

    Hi!

    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,
    Yigit

    #944130

    Hi 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

    #944139

    Hi,

    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,
    Yigit

    #944144

    The 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

    #944152

    Hi!

    Could you please post FTP and WP admin logins here privately so we can look into it? :)

    Best regards,
    Yigit

    #944205

    if you add more than one font please do all fonts ( different names ) in one rule together or
    rename that function

    On 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 twice

    #944208

    Or 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;
    }
    #944477

    Hi,

    Thanks for sharing @guenni007, much appreciated :-)

    Best regards,
    Rikard

    #946794
    This reply has been marked as private.
    #946849

    Hi,

    I edited Functions.php file and it should be fine. I was not able to confirm. I am getting following error.
    I tried adding http:// and https:// and neither worked. Please share full link of your website.

    Best regards,
    Yigit

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.