Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Custom web fonts, is a relative recent invention, that allows us to bring in style sheets, with new fonts that we can use on our website. That way we're no longer restricted by the very limiting, font families that used to be the only fonts that we could use, on the web. In designing this theme, I used two custom fonts, and also a custom icon font set. The custom font is the Sans Serif font you see here in the title, and also in the meta content it's called Lotto, and I also used a font called PT Serif for the main body content here.
In addition, I want to use the, Font Awesome Icon Font Library to make icons, within my site. Custom web fonts, are based on CSS. So, to, activate a new custom web font or, an icon font on our site, we need to import that style sheet into our site. The call to style sheets, should always be done in the head section of your page markup. And it might therefore seem logical, to add these calls right into the header.php template. But in WordPress we have a much more advanced option, called Enqueuing.
By enqueuing styles and scripts, we can control where, when and how each style sheet and each script is called, and what the tendencies each of them have. In enqueuing of styles and scripts, is done from functions.php. In the previous movie, I mentioned this enqueuing and here you can see it. We have a function, inside functions.php or rather an action, called WP enqueue scripts. And these actions, runs all the different, enqueue functions.
Here we have WP enqueue style, which ques up the style sheet for our site and we also have a couple of scripts. So, what we're going to do now is call in the style sheets, for this custom fonts using the same functions. First, I have to go and find the actual style sheets. So, I'll start with Google Fonts. Here I'm going to search for the fonts I need, so that was Lotto, here it is. So, I'm going to add that to my collection, and then it was PT Serif and, I'm going to add that to my collection. And once I have the two fonts I need, I'm going to go to the bottom here and click Use.
And this takes me to, the page where I can, define which font weights I want. And this is based on my design, so here I'm going to select, Thin 100 and then 400 Normal and Italic, Bold 700 and also Ultra Bold 900 and Italic. And for PT Serif, I'm going to use all four. Once I've selected the font weights I want, Google Web Font will automatically generate, a custom CSS style sheet for me, that I can include in several different ways.
So, down here, we have the, code examples that we can use. So, I'm going to go and just copy out. The link to, this style sheet here. And then I'll go back to, my functions.php file, and create a new function. So I'll go and say, WP enqueue, and then I'll select, Enqueue Style and here I have to set a handle. So that would be the name of the style. The, common handle is My Simone Styles. Here I'm going to say, my Simone at Google fonts.
And then I have to say comma, and then the link directly to the style sheet, and then I'll end my line with a semi-colon. And that's actually all I need to do, to get, this style sheet to queue up in the head section of my makeup. Now before I save, I am going to go and grab the same style sheet from Font Awesome as well,if you're not familiar with Font Awesome. It's, an icon font library that allows us to add really cool icons to our site, as if they were fonts. Here you see you have, hundreds of icons we can use.
Now what I'm interested in right now is how to get these icons, onto my site, so I'm going to go to Get Started, and scroll down and here you see the easiest way of including Font Awesome in your site, is to call the, BootstrapCDN Style Sheet. So, I'm going to go copy the style sheet here, and then I'll make another function exactly the same, WPenqueue Style, I'll set this name to My-Simone- Fontawesome, comma and then paste in URL.
And here you see this URL is actually not complete, so I'm going to print http; in front of it, and put a semi colon at the end, and now I can save the file, and know that now all these style sheets are going to be cued up. But of course, you want to test that to make sure that everything works right. So now I can go back to the browser, and here when I reload the page. You'll see, nothing happen and that's exactly what you can expect because although we pulled in the fonts, we haven't actually told, WordPress how to use them yet.
To see if the fonts actually get queued up, we're going to use the developer tools here. So I can go, right-click anywhere and select, Inspect Element, and then I'll go to Resources. Frames, Local Host and here you have a list of all the different things that are loaded up, including, images, scripts and style sheets. So if I select, Style Sheets and scroll down, you'll see here we have a whole bunch of different style sheets that have been loaded, most importantly, fontsawesome.css, which is the one we just called for, and also this one, which is just called CSS.
Where you can see here it says, Lotto and when we scroll down, PT Serif. So that means, we now have our styles queued up, and all we need to do is go into our styles.css file and tell WordPress, where we want to apply, those fonts.
Get unlimited access to all courses for just $25/month.Become a member
58 Video lessons · 60275 Viewers
61 Video lessons · 92844 Viewers
82 Video lessons · 104234 Viewers
56 Video lessons · 107293 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.