Here is my Tailwind configuration :
module.exports = {
content: ["./index.php", "./app/**/*.php", "./resources/**/*.{php,vue,js}"],
theme: {
extend: {
fontFamily: {
'TTFirsNeue': ['TT Firs Neue'],
'icomoon': ['icomoon'],
},
colors: {
},
typography: (theme) => ({
DEFAULT: {
css: {
h1: {
'font-family': theme('fontFamily.TTFirsNeue'),
'font-weight': '600',
'text-transform': 'uppercase',
},
h2: {
'font-family': theme('fontFamily.TTFirsNeue'),
'font-size': '46px',
'font-weight': '800',
'text-transform': 'uppercase',
'margin-top': '.5em',
'margin-bottom': '.5em',
},
a: {
'&:not(.go-to-next-section)': {
'font-weight': 'bold',
'text-decoration': 'underline',
'color': '#AB8ED9',
'font-style': 'italic'
},
},
p: {
'line-height': '1.5rem',
},
},
},
}),
},
},
plugins: [
require('@tailwindcss/typography'),
require('@tailwindcss/forms'),
function ({ addVariant }) {
addVariant('child', '& > *');
addVariant('child-hover', '& > *:hover');
},
],
};
Within my app.css, I declared the fonts like this (then I import app.css in editor.css) :
@font-face {
font-family: 'TT Firs Neue';
src: url('fonts/TTFirsNeue-Medium.eot');
src: local('TT Firs Neue Medium'), local('TTFirsNeue-Medium'),
url('fonts/TTFirsNeue-Medium.eot?#iefix') format('embedded-opentype'),
url('fonts/TTFirsNeue-Medium.woff2') format('woff2'),
url('fonts/TTFirsNeue-Medium.woff') format('woff'),
url('fonts/TTFirsNeue-Medium.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'TT Firs Neue';
src: url('fonts/TTFirsNeue-MediumItalic.eot');
src: local('TT Firs Neue Medium Italic'), local('TTFirsNeue-MediumItalic'),
url('fonts/TTFirsNeue-MediumItalic.eot?#iefix') format('embedded-opentype'),
url('fonts/TTFirsNeue-MediumItalic.woff2') format('woff2'),
url('fonts/TTFirsNeue-MediumItalic.woff') format('woff'),
url('fonts/TTFirsNeue-MediumItalic.ttf') format('truetype');
font-weight: normal;
font-style: italic;
}
@font-face {
font-family: 'TT Firs Neue';
src: url('fonts/TTFirsNeue-Bold.eot');
src: local('TT Firs Neue Bold'), local('TTFirsNeue-Bold'),
url('fonts/TTFirsNeue-Bold.eot?#iefix') format('embedded-opentype'),
url('fonts/TTFirsNeue-Bold.woff2') format('woff2'),
url('fonts/TTFirsNeue-Bold.woff') format('woff'),
url('fonts/TTFirsNeue-Bold.ttf') format('truetype');
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: 'TT Firs Neue';
src: url('fonts/TTFirsNeue-BoldItalic.eot');
src: local('TT Firs Neue Bold Italic'), local('TTFirsNeue-BoldItalic'),
url('fonts/TTFirsNeue-BoldItalic.eot?#iefix') format('embedded-opentype'),
url('fonts/TTFirsNeue-BoldItalic.woff2') format('woff2'),
url('fonts/TTFirsNeue-BoldItalic.woff') format('woff'),
url('fonts/TTFirsNeue-BoldItalic.ttf') format('truetype');
font-weight: bold;
font-style: italic;
}
@font-face {
font-family: 'TT Firs Neue';
src: url('fonts/TTFirsNeue-ExtraBold.eot');
src: local('TT Firs Neue ExtraBold'), local('TTFirsNeue-ExtraBold'),
url('fonts/TTFirsNeue-ExtraBold.eot?#iefix') format('embedded-opentype'),
url('fonts/TTFirsNeue-ExtraBold.woff2') format('woff2'),
url('fonts/TTFirsNeue-ExtraBold.woff') format('woff'),
url('fonts/TTFirsNeue-ExtraBold.ttf') format('truetype');
font-weight: 800;
font-style: normal;
}
@font-face {
font-family: 'TT Firs Neue';
src: url('fonts/TTFirsNeue-ExtraBoldItalic.eot');
src: local('TT Firs Neue ExtraBold Italic'), local('TTFirsNeue-ExtraBoldItalic'),
url('fonts/TTFirsNeue-ExtraBoldItalic.eot?#iefix') format('embedded-opentype'),
url('fonts/TTFirsNeue-ExtraBoldItalic.woff2') format('woff2'),
url('fonts/TTFirsNeue-ExtraBoldItalic.woff') format('woff'),
url('fonts/TTFirsNeue-ExtraBoldItalic.ttf') format('truetype');
font-weight: 800;
font-style: italic;
}
@font-face {
font-family: 'TT Firs Neue';
src: url('fonts/TTFirsNeue-Italic.eot');
src: local('TT Firs Neue Italic'), local('TTFirsNeue-Italic'),
url('fonts/TTFirsNeue-Italic.eot?#iefix') format('embedded-opentype'),
url('fonts/TTFirsNeue-Italic.woff2') format('woff2'),
url('fonts/TTFirsNeue-Italic.woff') format('woff'),
url('fonts/TTFirsNeue-Italic.ttf') format('truetype');
font-weight: normal;
font-style: italic;
}
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?lfoop7');
src: url('fonts/icomoon.eot?lfoop7#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?lfoop7') format('truetype'),
url('fonts/icomoon.woff?lfoop7') format('woff'),
url('fonts/icomoon.svg?lfoop7#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
}
[class^="icon-"],
[class*=" icon-"] {
/* use !important to prevent issues with browser extensions that change fonts */
font-family: 'icomoon' !important;
speak: never;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-diamond:before {
content: "\e900";
}
My theme.json :
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"color": {
"palette": [
{
"slug": "primary",
"color": "#525ddc",
"name": "Primary"
}
],
"custom": false,
"customGradient": false,
"defaultPalette": false,
"defaultGradients": false
},
"custom": {
"spacing": {},
"typography": {
"font-size": {},
"line-height": {}
}
},
"spacing": {
"padding": true,
"units": ["px", "%", "em", "rem", "vw", "vh"]
},
"typography": {
"customFontSize": false,
"fontFamilies": [
{
"fontFamily": "icomoon",
"name": "icomoon",
"slug": "icomoon",
"fontFace": [
{
"fontFamily": "icomoon",
"src": ["file:./resources/fonts/icomoon.ttf"]
}
]
},
{
"fontFamily": "TT Firs Neue",
"name": "TT Firs Neue",
"slug": "tt-firs-neue",
"fontFace": [
{
"fontFamily": "TT Firs Neue",
"fontWeight": "normal",
"src": ["file:./resources/fonts/icoTTFirsNeue-Medium.ttf"]
},
{
"fontFamily": "TT Firs Neue",
"fontWeight": "normal",
"fontStyle": "italic",
"src": ["file:./resources/fonts/icoTTFirsNeue-MediumItalic.ttf"]
},
{
"fontFamily": "TT Firs Neue",
"fontWeight": "bold",
"src": ["file:./resources/fonts/icoTTFirsNeue-Bold.ttf"]
},
{
"fontFamily": "TT Firs Neue",
"fontWeight": "bold",
"fontStyle": "italic",
"src": ["file:./resources/fonts/icoTTFirsNeue-BoldItalic.ttf"]
},
{
"fontFamily": "TT Firs Neue",
"fontWeight": 800,
"src": ["file:./resources/fonts/icoTTFirsNeue-ExtraBold.ttf"]
},
{
"fontFamily": "TT Firs Neue",
"fontWeight": 800,
"fontStyle": "italic",
"src": ["file:./resources/fonts/icoTTFirsNeue-ExtraBoldItalic.ttf"]
}
]
}
]
}
}
}
The fonticon (icomoon) is working, but the TT Firs Neue is not (within the editor, on the frontend it’s working).
What I don’t understand is why the @font-face relative URLs in my app.css are working on the frontend but not within the editor (instead of the url to mysite.com/app/themes/mytheme/ressources/fonts/… it’s trying to load the fonts at mysite.com/fonts/… )
Should I just remove the @font-face from the CSS files and just add them to the theme.json ? (I tried, but then it’s not working on the frontend anymore). In the end if I have to fill the CSS files and the theme.json, it feels like double the work.
As you can see I’m kind of lost here
I just would like to know the proper and most efficient way of using custom fonts with Sage and Gutenberg.