Header.php to add Google fonts

This topic contains 25 replies, has 3 voices, and was last updated by  tinamama 4 years, 10 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #491049

    tinamama
    Full Member
    Post count: 317

    So I am using Supreme Directory theme for V2…and I want to use Google fonts. I know I need to add code to the header.php file…but that file doesn’t show in the Supreme Directory theme editor files, only in the parent theme (Directory Starter)…so should I be putting the code there? But won’t that be overwritten on next update? But I imagine it would also be overwritten on next update in Supreme Directory also, even if it did have a copy of the file there…not sure how to deal with a child of a child…that’s not possible is it?

    So how do I deal with adding code for Google Fonts on a child theme? Where do I put this code? Help?

    #491060

    Alex Rollin
    Moderator
    Post count: 27815

    You can use a plugin like Easy Updates Manager to disable updates for Supreme, or change the name so it doesn’t receive updates.

    #491132

    tinamama
    Full Member
    Post count: 317

    I’m trying to avoid adding MORE plugins to my site.

    So basically you’re saying that there isn’t a way to do this? That the Google fonts code WILL be overwritten whenever an update to the Header.php file happens? I suppose I can work with that if it means that I have to keep an eye on the site each time I get an update from the theme and make sure to watch for the fonts changing…and then add the code back. I suppose that’s not a huge deal since I’ll be the one updating things. Just an extra step, but if I know to watch for it, and I know what to do, I can do that. I can’t imagine they’d be changing that file that often anyway.

    And then what about my other question…would I be putting the code in the header.php file in Directory Starter, since it’s not showing in the editor for Supreme? I assume that’s because Supreme didn’t make any changes to the header?

    #491136

    tinamama
    Full Member
    Post count: 317

    Well now here’s an interesting idea….grandchild themes? I had not ever heard of these!

    https://www.wp-code.com/wordpress-snippets/wordpress-grandchildren-themes/

    The concept does seem kinda messy though…seems like it would be easier to go with what I talked about above…putting the code into the parent file and keeping an eye on if an update overwrites it and just putting it back in…what do you think? I don’t even know if I am understanding all this properly. I really don’t want anything that would slow down my site.

    #491142

    Alex Rollin
    Moderator
    Post count: 27815

    When you customize with PHP, we recommend you do it with code snippets stored in the code snippets plugin.

    https://wpgeodirectory.com/docs-v2/faq/customizing/#custom-code

    #491153

    tinamama
    Full Member
    Post count: 317

    I have the code snippets plugin on another site, and it is my understanding that it adds code to the functions.php file? Google fonts, I believe from reading their info, needs to add code to the header.php file. I do know of a plugin that allows me to add to the header…but again, I am trying to avoid having to use ANOTHER plugin. I already have too many and am trying to figure out how to get rid of some.

    #491324

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    with a php snipppet you can make the code appear in the section of your site without adding code to header.php

    WP Actions and filters allow doing so.

    Example:

    
    function wp_add_google_fonts() {
     
    wp_enqueue_style( 'wp-google-fonts', 'http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,400,700,300', false ); 
    }
     
    add_action( 'wp_enqueue_scripts', 'wp_add_google_fonts' );

    Thanks

    #491331

    tinamama
    Full Member
    Post count: 317

    Ok cool, good to know. Still adds another plugin to my site. Something I would like to avoid. 🙂

    #491373

    tinamama
    Full Member
    Post count: 317

    Ok, I just found this article: https://www.namehero.com/startup/where-to-put-custom-code-in-wordpress-hint-use-a-plugin/

    That looks so straightforward and easy that even *I*, someone that is decidedly NOT a code geek, can do it… what do you think? Would this kind of plugin slow down my site any more? Because I am trying to avoid slowing my site down more…it’s already got an F for speed that I need to fix, therefore I do NOT want to add more unnecessary plugins, but this seems like maybe it could be a feasible alternative?

    I don’t know enough about this kind of thing to know for sure, so I’m asking for those of you with this kind of knowledge to help me sort this out… Thanks in advance!

    #491617

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    you really don’t need to go through all that to avoid installing 1 plugin.

    Code snippet might slow down your website for a few milliseconds max.

    What’s most likely responsible for a slow site is an underpowered server.

    Thanks

    #491619

    Paolo
    Site Admin
    Post count: 31206
    This reply has been marked as private.
    #491633

    tinamama
    Full Member
    Post count: 317

    Good to know, thanks! So what do you suggest as a better solution for fonts?

    And when you say “underpowered server”…what exactly do you mean? Would that involve upgrading my hosting plan? I am on Siteground’s “GrowBig” plan currently.

    #491635

    Paolo
    Site Admin
    Post count: 31206

    For fonts there are not many alternatives. But if you feel like the site is slow, you shouldn’t add more, unless you are willing to upgrade your hosting plan, probably it’s better to use a web default font.

    The GrowBig plan from Siteground’s is just another shared server with a fancy name.

    For a well-performing site, you should consider a decent VPS.

    Thanks

    #491638

    tinamama
    Full Member
    Post count: 317

    Ugh, I just read this: https://wpgeodirectory.com/docs/server-requirements/

    So it looks like I do need to upgrade… I cannot currently afford $80/month. Nor do I want to leave Siteground. I just moved to them recently and REALLY like them.

    Well, I guess that puts this project on hold for a while. At least until I can figure this out. Drat.

    #491640

    Paolo
    Site Admin
    Post count: 31206

    $80/month? we don’t pay that much and we are on a stellar dedicated server.

    The GD Optimized servers offered by spectrum cost $20/month.

    Thanks

Viewing 15 posts - 1 through 15 (of 26 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket