Header.php to add Google fonts
This topic contains 25 replies, has 3 voices, and was last updated by tinamama 5 years, 5 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
June 5, 2019 at 6:35 pm #491049
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?
June 5, 2019 at 7:19 pm #491060You can use a plugin like Easy Updates Manager to disable updates for Supreme, or change the name so it doesn’t receive updates.
June 6, 2019 at 12:08 am #491132I’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?
June 6, 2019 at 12:49 am #491136Well 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.
June 6, 2019 at 2:11 am #491142When 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
June 6, 2019 at 4:01 am #491153I 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.
June 6, 2019 at 6:28 pm #491324Hi,
with a php snipppet you can make the code appear in the
section of your site without adding code to header.phpWP 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
June 6, 2019 at 7:01 pm #491331Ok cool, good to know. Still adds another plugin to my site. Something I would like to avoid. 🙂
June 6, 2019 at 11:54 pm #491373Ok, 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!
June 7, 2019 at 6:29 pm #491617Hi,
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
June 7, 2019 at 6:30 pm #491619This reply has been marked as private.June 7, 2019 at 8:01 pm #491633Good 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.
June 7, 2019 at 8:23 pm #491635For 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
June 7, 2019 at 8:29 pm #491638Ugh, 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.
June 7, 2019 at 8:31 pm #491640$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
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket