Add your own font
Kingdom theme includes different fonts, as any Shopify theme, that can be selected from the Theme Customizer > General > Typography (screenshot). But if you decide to use a custom font, there are a few methods to do this:
1. Use the @font-face declaration (add your own font files)
Please start by uploading your new font in Content > Files. The best font file format for compatibility with all browsers is the woff, or even better, woff2 format.
Open /snippets/head-variables.liquid and right at the top, remove the first 8 lines of code:
{%- assign headings_font = settings.headings_font -%}
{%- assign body_font = settings.body_font -%}
{%- unless headings_font.system? -%}
<link rel="preload" href="{{ headings_font | font_url }}" as="font" type="font/woff2" crossorigin>
{%- endunless -%}
{%- unless body_font.system? -%}
<link rel="preload" href="{{ body_font | font_url }}" as="font" type="font/woff2" crossorigin>
{%- endunless -%}
Now, go a bit further and identify the place where the current fonts are created, and delete those lines as well:
echo headings_font | font_face: font_display: 'swap'
echo body_font | font_face: font_display: 'swap'
assign body_font_medium = body_font | font_modify: 'weight', '500'
assign body_font_semibold = body_font | font_modify: 'weight', '600'
assign body_font_bold = body_font | font_modify: 'weight', '700'
assign body_font_italic = body_font | font_modify: 'style', 'italic'
assign body_font_bold_italic = body_font_bold | font_modify: 'style', 'italic'
if body_font_medium
echo body_font_medium | font_face: font_display: 'swap'
endif
if body_font_semibold
echo body_font_semibold | font_face: font_display: 'swap'
endif
if body_font_bold
echo body_font_bold | font_face: font_display: 'swap'
endif
if body_font_italic
echo body_font_italic | font_face: font_display: 'swap'
endif
if body_font_bold_italic
echo body_font_bold_italic | font_face: font_display: 'swap'
endif
Go down to where you see :root, and paste the following code right above that place:
@font-face {
font-family: "MyFont";
src: url('Your_font_file_URL') format("woff");
}
Add this declaration for all the fonts that you wish to use (if you want to change two fonts, one for headings, one for body, you'll need to font declarations, with the names you declare. If your font has style variations (italic, bold), you need to add font files for those as well, like this:
@font-face {
font-family: "MyFont";
src: url('Your_font_file_URL') format("woff");
}
@font-face {
font-family: "MyFont";
font-weight: 500;
src: url('Your_font_file_URL') format("woff");
}
@font-face {
font-family: "MyFont";
font-weight: 700;
src: url('Your_font_file_URL') format("woff");
}
@font-face {
font-family: "MyFont";
font-weight: 400;
font-style: italic;
src: url('Your_font_file_URL') format("woff");
}
Please double check that the font complete URL is used as generated by Shopify when the file is uploaded. The URL will be in this format: https://cdn.shopify.com/s/files/1/0506/9622/0000/files/font_name.woff2?v=1685962551
Now that your font is ready to be loaded, go a bit further down and identify the font variables:
/* Font variables */
--font-stack-headings: {{ headings_font.family }}, {{ headings_font.fallback_families }};
--font-weight-headings: {{ headings_font.weight }};
--font-style-headings: {{ headings_font.style }};
--font-stack-body: {{ body_font.family }}, {{ body_font.fallback_families }};
--font-weight-body: {{ body_font.weight }};
--font-style-body: {{ body_font.style }};
{%- if body_font_medium -%}
--font-weight-body-medium: 500;
{%- elsif body_font_semibold %}
--font-weight-body-medium: 600;
{% elsif body_font_bold %}
--font-weight-body-medium: 700;
{%- endif -%}
{%- if body_font_semibold -%}
--font-weight-body-semibold: 600;
{%- else %}
--font-weight-body-semibold: 700;
{% endif %}
--font-weight-body-bold: 700;
You'll have to delete this code and hard code your own font stack here, like this:
/* Font variables */
--font-stack-headings: "MyFont", sans-serif;
--font-weight-headings: 400;
--font-style-headings: normal;
--font-stack-body: "MyFont", sans-serif;
--font-weight-body: 400;
--font-weight-body-medium: 500;
--font-weight-body-semibold: 600;
--font-weight-body-bold: 700;
--font-style-body: normal;
You can have three different fonts, or use the same font for all typography, just make sure that you add the source files properly for all the fonts that you wish to use.
If you have any issue please again double check that the font name added in the code matches the font name file uploaded on the Shopify server.
If your theme version is 3.4.2 or lower
Open /assets/css_main.scss.liquid file. Go at section #Fonts and just before the fonts variables, insert the new font face declaration of your new font (screenshot). Here's an example:
@font-face {
font-family: "MyFont";
src: url('{{ "MyFont.woff" | asset_url }}') format("woff");
}
Add such declaration for all the fonts that you might want to include. Next, you have to change the font variables, from the settings values to your own value.
Headings fonts:
Please search for this block of code and remove it completely!!
// Headings font load
{{ settings.typography_headings_new | font_face: font_display: 'swap' }}
{% assign headings_font = settings.typography_headings_new %}
$font-stack-header: {{ headings_font.family }}, {{ headings_font.fallback_families }};
$font-weight-header: {{ headings_font.weight }};
$font-style-header: {{ headings_font.style }};
@mixin headings-font(){
font-family: $font-stack-header;
font-weight: $font-weight-header;
font-style: $font-style-header;
}
$headingsFontBoldWeight: {{ headings_font.weight }};
{% assign headings_font_bold = headings_font | font_modify: 'weight', 'bolder' %}
{% if headings_font_bold %}
{{ headings_font_bold | font_face: font_display: 'swap' }}
$headingsFontBoldWeight: {{ headings_font_bold.weight }};
{% endif %}
Replace the deleted code with this new code where you need to insert your own values:
$font-stack-header: 'MyFont', serif;
$font-weight-header: 500;
$font-style-header: normal;
@mixin headings-font(){
font-family: $font-stack-header;
font-weight: $font-weight-header;
font-style: $font-style-header;
}
$headingsFontBoldWeight: 700;
This will make sure that your new font will be taken as the headings font, and of course, you need to provide a fallback, in our example it's serif.
Body fonts:
The code that needs to be removed is:
// Body font load
{% assign body_font = settings.typography_body_new %}
{{ body_font | font_face: font_display: 'swap' }}
$font-stack-body: {{ body_font.family }}, {{ body_font.fallback_families }};
$font-weight-body: {{ body_font.weight }};
$font-style-body: {{ body_font.style }};
{% assign body_font_medium = body_font | font_modify: 'weight', '500' %}
{% assign body_font_semibold = body_font | font_modify: 'weight', '600' %}
{% assign body_font_bold = body_font | font_modify: 'weight', '700' %}
{% assign body_font_italic = body_font | font_modify: 'style', 'italic' %}
{% assign body_font_bold_italic = body_font_bold | font_modify: 'style', 'italic' %}
$bodyFontMediumWeight: {{ body_font.weight }};
{% if body_font_medium %}
{{ body_font_medium | font_face: font_display: 'swap' }}
$bodyFontMediumWeight: {{ body_font_medium.weight }};
{% else %}
{% if body_font_semibold %}
$bodyFontMediumWeight: {{ body_font_semibold.weight }};
{% elsif body_font_bold %}
$bodyFontMediumWeight: {{ body_font_bold.weight }};
{% endif %}
{% endif %}
$bodyFontSemiboldWeight: {{ body_font.weight }};
{% if body_font_semibold %}
{{ body_font_semibold | font_face: font_display: 'swap' }}
$bodyFontSemiboldWeight: {{ body_font_semibold.weight }};
{% else %}
{% if body_font_bold %}
$bodyFontSemiboldWeight: {{ body_font_bold.weight }};
{% endif %}
{% endif %}
$bodyFontBoldWeight: {{ body_font.weight }};
{% if body_font_bold %}
{{ body_font_bold | font_face: font_display: 'swap' }}
$bodyFontBoldWeight: {{ body_font_bold.weight }};
{% endif %}
{% if body_font_italic %}
{{ body_font_italic | font_face: font_display: 'swap' }}
{% endif %}
{% if body_font_bold_italic %}
{{ body_font_bold_italic | font_face: font_display: 'swap' }}
{% endif %}
@mixin body-font(){
font-family: $font-stack-body;
font-weight: $font-weight-body;
font-style: $font-style-body;
}
And the replacement code is:
$font-stack-body: 'MyFont', serif;
$font-weight-body: 400;
$font-style-body: normal;
@mixin body-font(){
font-family: $font-stack-body;
font-weight: $font-weight-body;
font-style: $font-style-body;
}
$bodyFontMediumWeight: 500;
$bodyFontSemiboldWeight: 600;
$bodyFontBoldWeight: 700;
Menus and logo text font:
The original code that needs to be deleted is:
// Logo & menus
{% assign menu_font = settings.typography_menus_new %}
{{ menu_font | font_face }}
$font-stack-menu: {{ menu_font.family }}, {{ menu_font.fallback_families }};
$font-weight-menu: {{ menu_font.weight }};
$font-style-menu: {{ menu_font.style }};
$menuFontRegularWeight: {{ menu_font.weight }};
{% assign menu_font_bold = menu_font | font_modify: 'weight', '600' %}
$menuFontBoldWeight: 600;
{% if menu_font_bold %}
{{ menu_font_bold | font_face }}
{% else -%}
{% assign menu_font_bold = menu_font | font_modify: 'weight', 'bolder' %}
{{ menu_font_bold | font_face }}
{% endif %}
{% if menu_font_bold %}
$menuFontBoldWeight: {{ menu_font_bold.weight }};
{% endif %}
@mixin font-menu(){
font-family: $font-stack-menu;
font-weight: $font-weight-menu;
font-style: $font-style-menu;
}
The new code with your own font name value (don't forget to replace 'MyFont' with your own font name in this code):
$font-stack-menu: 'MyFont', serif;
$font-weight-menu: 300;
$font-style-menu: normal;
@mixin font-menu(){
font-family: $font-stack-menu;
font-weight: $font-weight-menu;
font-style: $font-style-menu;
}
$menuFontRegularWeight: 300;
$menuFontBoldWeight: 700;
For the quote font:
The original code:
// Quote fonts load
{{ settings.typography_quotes_new | font_face: font_display: 'swap' }}
{% assign quotes_font = settings.typography_quotes_new %}
$font-stack-quotes: {{ quotes_font.family }}, {{ quotes_font.fallback_families }};
$font-weight-quotes: {{ quotes_font.weight }};
$font-style-quotes: {{ quotes_font.style }};
$font-size-quotes: {{ settings.typography_quotes_new_size }};
The new code:
$font-stack-quotes: 'MyFont', serif;
$font-weight-quotes: 300;
$font-style-quotes: italic;
$font-size-quotes: {{ settings.typography_quotes_new_size }};
2. Use Google Fonts
After you select the font you need to use from Google fonts, a code will be generated for you to insert in the theme ( screenshot).
Please embed the generated code in the t heme.liquid file, just before the </head> closing tag (screenshot ).
For example, for the Poiret One font the code generated by Google is:
<link href="https://fonts.googleapis.com/css?family=Poiret+One" rel="stylesheet">
Then go back at STEP 1, and based on your theme version, apply the steps in order for the theme to use your font. Just skip the "@font-face" declaration, but the rest is the same.. You will be using the selected font from Google instead. So in all above examples, where we've used "MyFont", here it will be "Poiret One".