Make WordPress Core

Changeset 55266

Timestamp:
02/07/2023 03:29:30 PM (18 months ago)
Author:
audrasjb
Message:

Twenty Seventeen: Bundle Google Fonts locally.

This changeset bundles the Google Fonts used by Twenty Seventeen locally in the theme folder, instead of loading them from Google servers. Existing font stylesheet handles are maintained for backward compatibilily.

Props luminuu, audrasjb, jhoffmann, jffng, paapst, cbirdsong, webcommsat, kau-boy, MatthiasReinholz, sabernhardt, hellofromTonya, JeffPaul, davidbaumwald, desrosj, bedas, poena, costdev, azaozz, aristath.
See #55985.

Location:
trunk/src/wp-content/themes/twentyseventeen
Files:
36 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyseventeen/functions.php

    r54902 r55266  
    122122    /*
    123123     * This theme styles the visual editor to resemble the theme style,
    124      * specifically font, colors, and column width.
    125      */
    126     add_editor_style( array( 'assets/css/editor-style.css', twentyseventeen_fonts_url() ) );
     124     * specifically font, colors, and column width. When fonts are
     125     * self-hosted, the theme directory needs to be removed first.
     126     */
     127    $font_stylesheet = str_replace(
     128        array( get_template_directory_uri() . '/', get_stylesheet_directory_uri() . '/' ),
     129        '',
     130        twentyseventeen_fonts_url()
     131    );
     132    add_editor_style( array( 'assets/css/editor-style.css', $font_stylesheet ) );
    127133
    128134    // Load regular editor styles into the new block-based editor.
     
    284290add_action( 'template_redirect', 'twentyseventeen_content_width', 0 );
    285291
    286 /**
    287  * Register custom fonts.
    288  */
    289 function twentyseventeen_fonts_url() {
    290     $fonts_url = '';
    291 
    292     /*
    293      * translators: If there are characters in your language that are not supported
    294      * by Libre Franklin, translate this to 'off'. Do not translate into your own language.
    295      */
    296     $libre_franklin = _x( 'on', 'Libre Franklin font: on or off', 'twentyseventeen' );
    297 
    298     if ( 'off' !== $libre_franklin ) {
    299         $font_families = array();
    300 
    301         $font_families[] = 'Libre Franklin:300,300i,400,400i,600,600i,800,800i';
    302 
    303         $query_args = array(
    304             'family'  => urlencode( implode( '|', $font_families ) ),
    305             'subset'  => urlencode( 'latin,latin-ext' ),
    306             'display' => urlencode( 'fallback' ),
    307         );
    308 
    309         $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
    310     }
    311 
    312     return esc_url_raw( $fonts_url );
    313 }
     292if ( ! function_exists( 'twentyseventeen_fonts_url' ) ) :
     293    /**
     294     * Register custom fonts.
     295     *
     296     * @since Twenty Seventeen 1.0
     297     * @since Twenty Seventeen 3.2 Replaced Google URL with self-hosted fonts.
     298     *
     299     * @return string Fonts URL for the theme.
     300     */
     301    function twentyseventeen_fonts_url() {
     302        $fonts_url = '';
     303
     304        /*
     305         * translators: If there are characters in your language that are not supported
     306         * by Libre Franklin, translate this to 'off'. Do not translate into your own language.
     307         */
     308        $libre_franklin = _x( 'on', 'Libre Franklin font: on or off', 'twentyseventeen' );
     309
     310        if ( 'off' !== $libre_franklin ) {
     311            $fonts_url = get_template_directory_uri() . '/assets/fonts/font-libre-franklin.css';
     312        }
     313
     314        return esc_url_raw( $fonts_url );
     315    }
     316endif;
    314317
    315318/**
     
    317320 *
    318321 * @since Twenty Seventeen 1.0
     322
    319323 *
    320324 * @param array  $urls          URLs to print for resource hints.
     
    332336    return $urls;
    333337}
    334 add_filter( 'wp_resource_hints', 'twentyseventeen_resource_hints', 10, 2 );
     338add_filter( 'wp_resource_hints', 'twentyseventeen_resource_hints', 10, 2 );
    335339
    336340/**
     
    452456function twentyseventeen_scripts() {
    453457    // Add custom fonts, used in the main stylesheet.
    454     wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
     458    $font_version = ( 0 === strpos( (string) twentyseventeen_fonts_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     459    wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), $font_version );
    455460
    456461    // Theme stylesheet.
     
    518523    wp_enqueue_style( 'twentyseventeen-block-editor-style', get_theme_file_uri( '/assets/css/editor-blocks.css' ), array(), '20220912' );
    519524    // Add custom fonts.
    520     wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
     525    $font_version = ( 0 === strpos( (string) twentyseventeen_fonts_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     526    wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), $font_version );
    521527}
    522528add_action( 'enqueue_block_editor_assets', 'twentyseventeen_block_editor_styles' );
  • trunk/src/wp-content/themes/twentyseventeen/readme.txt

    r55024 r55266  
    5353License: SIL Open Font License, version 1.1.
    5454Source: http://fontawesome.io/
     55
     56
     57
     58
     59
    5560
    5661Bundled header image, Copyright Alvin Engler
Note: See TracChangeset for help on using the changeset viewer.