Skip to content

Define Your Font Family Stack (fallback font)

Important

Rather then using custom code it's recommended to use the Font Manager to define your fonts and font stacks.

Whenever you set a font via the customizer or theme elements it will give the element a font-family value equal to the selected font without any fallback value (some popular fonts like Open Sans do have a default fallback font stack). You can use the "wpex_get_font_family_stack" filter to define your custom font stack for any font used on the site.

/**
 * Define font family stacks.
 *
 * @link https://totalwptheme.com/docs/snippets/define-font-family-stack/
 */
add_filter( 'wpex_get_font_family_stack', function( $font_family, $stack ) {
	if ( 'your-font' == $font_family ) {
		$stack = 'sans-serif';
	}
	return $stack;
}, 10, 2 );
All PHP snippets should be added via child theme's functions.php file or via a plugin.
We recommend Code Snippets (100% Free) or WPCode (sponsored)
Related Snippets
No related snippets found
Back To Top