Home / Admin / Generate Press Custom Font
Duplicate Snippet

Embed Snippet on Your Site

Generate Press Custom Font

This snippet allows developers & designers the ability to add custom fonts to generate press themed websites

Joe McCorison PRO
<10
Code Preview
php
<?php
/**
 * Adding custom fonts to Generate Press
 * https://docs.generatepress.com/article/adding-local-fonts/
 */
// allows the following to be uploaded
add_filter( 'upload_mimes', function( $mimes ) {
    $mimes['woff']  = 'application/x-font-woff';
    $mimes['woff2'] = 'application/x-font-woff2';
    $mimes['ttf']   = 'application/x-font-ttf';
    $mimes['svg']   = 'image/svg+xml';
    $mimes['eot']   = 'application/vnd.ms-fontobject';
    return $mimes;
} );
// this snippet will show the font in Block editor, fonts need to be defined in Customizer > Additional CSS 
add_filter( 'block_editor_settings_all', function( $editor_settings ) {
    $css = wp_get_custom_css_post()->post_content;
    $editor_settings['styles'][] = array( 'css' => $css );
    return $editor_settings;
} );

Comments

Add a Comment