Community Forums › Forums › Archived Forums › General Discussion › Adding Google font: Is using header scripts area ok?
Tagged: Google fonts enqueue
- This topic has 4 replies, 2 voices, and was last updated 6 years, 3 months ago by dev.
-
AuthorPosts
-
January 9, 2018 at 5:21 pm #215249devParticipant
For a low-traffic site is it OK to put the Google font link in the Genesis, Theme Settings Header Scripts area?
I know the methodology is to use enqueue it via PHP in functions.php, but I was wondering just how much difference it would make by putting it in the Header Script area... which is faster to do and easier to explain and less prone to coding error.
Ideas? Opinions? Facts?
Thanks.
January 10, 2018 at 12:44 pm #215276MarcyParticipantIf there is already a Google font enqueued in the functions.php, and you don’t remove it, then it will still be loaded, and the new font in the Header Scripts will also be loaded. So that’s 2 fonts and 2 requests.
If you remove the fonts that are enqueued, then adding a new one in the Header Scripts can be OK. But if you’re already editing functions.php, then you might as well, just enqueue the new font.
Marcy | Amethyst Website Design | Twitter
January 10, 2018 at 4:21 pm #215288devParticipantGood advice and I thank you. The issue is that I have to explain over the phone how to add a Google font to a company site she is not allowed to give me access to. Trying to explain to a newbie how to deal with PHP on functions.php is a bit more involved than telling her to "put the Google Font link in the Gen. Header Script box."
What is the advantage of enqueuing the script vs. using the header box?
January 10, 2018 at 7:04 pm #215290MarcyParticipantWell, if it's too difficult to enqueue, then yes, you should just have them add the link in the Header Scripts box. You won't be "stepping on anyone's toes" per the post below. You'll just be adding an extra font and request. If the site is small, then you'll see very little difference. And I think the Header Scripts is better than the @import in style.css.
If you want to know the "reason" for enqueueing, then read the section
"Why Enqueue Scripts and Styles in WordPress?" explains it well.
http://www.wpbeginner.com/wp-tutorials/how-to-properly-add-javascripts-and-styles-in-wordpress/
Marcy | Amethyst Website Design | Twitter
January 11, 2018 at 10:12 am #215300devParticipantThe link above will work, but for Genesis I've had success doing it with this code for a style sheets and fonts:
//* Load the custom CSS file add_action( 'wp_enqueue_scripts', 'custom_load_custom_style_sheet' ); function custom_load_custom_style_sheet() { wp_enqueue_style( 'custom-stylesheet', CHILD_URL . '/custom.css', array(), PARENT_THEME_VERSION ); }
//* For Lato font, as an example add_action( 'wp_enqueue_scripts', 'sp_load_google_fonts' ); function sp_load_google_fonts() { wp_enqueue_style( 'google-font-lato', '//fonts.googleapis.com/css?family=Lato:300,700', array(), CHILD_THEME_VERSION ); }
That said, I'm not sure that using the Header Scripts box for a low-volume site to add a font or a style sheet will be so much LESS efficient than PHP code, such that it would make a difference in load time.
YMMV.
Thanks.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.