Skip to content
Docs

Add a custom font to the Stax theme

Stax includes the full Google Fonts list under Appearance > Customize > Typography, so check there first: see Typography. For a font that is not in the list, such as a licensed brand font, host the font files yourself, declare the font with @font-face and apply it with CSS.

  • Font files in WOFF2 format (add WOFF if you need to support very old browsers). Check that the font license allows web use.
  • A Stax child theme, so the files and the CSS survive theme updates.
  1. In your child theme folder (wp-content/themes/stax-child), create a folder named fonts.
  2. Upload the font files to it over FTP, one file per weight and style, for example brand-regular.woff2 and brand-bold.woff2.

Add one @font-face rule per file to the style.css of the child theme:

@font-face {
font-family: 'Brand Font';
src: url('fonts/brand-regular.woff2') format('woff2');
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'Brand Font';
src: url('fonts/brand-bold.woff2') format('woff2');
font-weight: 700;
font-style: normal;
font-display: swap;
}

The url() paths are relative to style.css. The name in font-family is the one you use in the next step.

Add CSS rules for the elements that should use the font, in the same style.css or in Appearance > Customize > Additional CSS:

/* Whole site */
body {
font-family: 'Brand Font', sans-serif;
}
/* Single post and page titles only */
h1.entry-title {
font-family: 'Brand Font', sans-serif;
font-weight: 700;
}

A font set in Customize > Typography for the same element can win over your rule. If your font does not show, inspect the element with the browser developer tools and copy the selector the theme uses, or reset that typography option to its default.

A font plugin such as Custom Fonts can store the files and write the @font-face rules for you. Follow the plugin’s own instructions for the upload, then apply the font as described above if the plugin does not do it.