Adding custom Google fonts
To further match your personal branding and/or taste
Adding Google fonts can change the appearance of your theme, wether it’s part of your personal branding .. our your just really fond of a font. Most Hammer themes use one or more Google fonts by default, and have a handpicked list of fonts ready to be used via the WordPress Customizer. You can add your own however.
Be sure to back-up your functions.php file. When somethings goes wrong, it tends to go wrong in a big way and end up in the notorious white screen of death.
- Pick a font by visiting the Google fonts website, e.g. “Open Sans“
- Click the Quick Use button
- Select the font weights you want to include, e.g. “Normal 400” and “Normal 400 Italic”
- Scroll down to where it reads “Add this code to your website”
- Remember both font name and weights, e.g. “Open Sans” and “400,400italic”
- Open up your functions.php file and find the
<themename>_fonts_url()
function - Copy and paste one of the excisting font references to create a new one
- Replace the font reference with the name of your new font
- Replace the font weights with the weights of your new font
- Your new font reference should look like:
if( 'off' !== _x( 'on', 'Open Sans font: on or off', '<textdomain>' ) ) { $fonts[] = 'Open Sans:400,400italic,700,700italic'; }
You can now use “Open Sans” in your style.css stylesheet like this:
body, button, input, select, textarea { font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; }