Make WordPress Core

Changeset 55267


Ignore:
Timestamp:
02/07/2023 03:43:01 PM (17 months ago)
Author:
audrasjb
Message:

Twenty Sixteen: Bundle Google Fonts locally.

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

Props garrett-eclipse, kjellr, ocean90, SergeyBiryukov, westonruter, luminuu, audrasjb, jhoffmann, jffng, paapst, cbirdsong, webcommsat, kau-boy, MatthiasReinholz, sabernhardt, hellofromTonya, JeffPaul, davidbaumwald, desrosj, bedas, poena, costdev, mukesh27, azaozz, aristath.
See #55985.

Location:
trunk/src/wp-content/themes/twentysixteen
Files:
66 added
2 edited

Legend:

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

    r54492 r55267  
    135135        /*
    136136         * This theme styles the visual editor to resemble the theme style,
    137          * specifically font, colors, icons, and column width.
    138          */
    139         add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) );
     137         * specifically font, colors, icons, and column width. When fonts are
     138         * self-hosted, the theme directory needs to be removed first.
     139         */
     140        $font_stylesheet = str_replace(
     141            array( get_template_directory_uri() . '/', get_stylesheet_directory_uri() . '/' ),
     142            '',
     143            twentysixteen_fonts_url()
     144        );
     145        add_editor_style( array( 'css/editor-style.css', $font_stylesheet ) );
    140146
    141147        // Load regular editor styles into the new block-based editor.
     
    242248 *
    243249 * @since Twenty Sixteen 1.6
     250 * @deprecated Twenty Sixteen 2.9 Disabled filter because, by default, fonts are self-hosted.
    244251 *
    245252 * @param array  $urls          URLs to print for resource hints.
     
    257264    return $urls;
    258265}
    259 add_filter( 'wp_resource_hints', 'twentysixteen_resource_hints', 10, 2 );
     266// add_filter( 'wp_resource_hints', 'twentysixteen_resource_hints', 10, 2 );
    260267
    261268/**
     
    307314if ( ! function_exists( 'twentysixteen_fonts_url' ) ) :
    308315    /**
    309      * Register Google fonts for Twenty Sixteen.
     316     * Register fonts for Twenty Sixteen.
    310317     *
    311318     * Create your own twentysixteen_fonts_url() function to override in a child theme.
    312319     *
    313320     * @since Twenty Sixteen 1.0
     321     * @since Twenty Sixteen 2.9 Replaced Google URL with self-hosted fonts.
    314322     *
    315      * @return string Google fonts URL for the theme.
     323     * @return string Fonts URL for the theme.
    316324     */
    317325    function twentysixteen_fonts_url() {
    318326        $fonts_url = '';
    319327        $fonts     = array();
    320         $subsets   = 'latin,latin-ext';
    321328
    322329        /*
     
    325332         */
    326333        if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) {
    327             $fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic';
     334            $fonts[] = 'merriweather';
    328335        }
    329336
     
    333340         */
    334341        if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) {
    335             $fonts[] = 'Montserrat:400,700';
     342            $fonts[] = 'montserrat';
    336343        }
    337344
     
    341348         */
    342349        if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) {
    343             $fonts[] = 'Inconsolata:400';
     350            $fonts[] = 'inconsolata';
    344351        }
    345352
    346353        if ( $fonts ) {
    347             $fonts_url = add_query_arg(
    348                 array(
    349                     'family'  => urlencode( implode( '|', $fonts ) ),
    350                     'subset'  => urlencode( $subsets ),
    351                     'display' => urlencode( 'fallback' ),
    352                 ),
    353                 'https://fonts.googleapis.com/css'
    354             );
     354            $fonts_url = get_template_directory_uri() . '/fonts/' . implode( '-plus-', $fonts ) . '.css';
    355355        }
    356356
     
    378378function twentysixteen_scripts() {
    379379    // Add custom fonts, used in the main stylesheet.
    380     wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
     380    $font_version = ( 0 === strpos( (string) twentysixteen_fonts_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     381    wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), $font_version );
    381382
    382383    // Add Genericons, used in the main stylesheet.
     
    437438    wp_enqueue_style( 'twentysixteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20221004' );
    438439    // Add custom fonts.
    439     wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
     440    $font_version = ( 0 === strpos( (string) twentysixteen_fonts_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     441    wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), $font_version );
    440442}
    441443add_action( 'enqueue_block_editor_assets', 'twentysixteen_block_editor_styles' );
  • trunk/src/wp-content/themes/twentysixteen/readme.txt

    r55024 r55267  
    5151License: GNU GPL, Version 2 (or later)
    5252Source: http://www.genericons.com
     53
     54Merriweather Font
     55Copyright 2016 The Merriweather Project Authors (https://github.com/EbenSorkin/Merriweather), with Reserved Font Name "Merriweather".
     56License: SIL Open Font License, 1.1, https://opensource.org/licenses/OFL-1.1
     57Source: https://fontsource.org/fonts/merriweather
     58
     59Montserrat Font
     60Copyright 2011 The Montserrat Project Authors (https://github.com/JulietaUla/Montserrat)
     61License: SIL Open Font License, 1.1, https://opensource.org/licenses/OFL-1.1
     62Source: https://fontsource.org/fonts/montserrat
     63
     64Inconsolata Font
     65Copyright 2006 The Inconsolata Project Authors (https://github.com/cyrealtype/Inconsolata)
     66License: SIL Open Font License, 1.1, https://opensource.org/licenses/OFL-1.1
     67Source: https://fontsource.org/fonts/inconsolata
    5368
    5469Image used in screenshot.png: A photo by Austin Schmid (https://unsplash.com/schmidy/), licensed under Creative Commons Zero(http://creativecommons.org/publicdomain/zero/1.0/)
Note: See TracChangeset for help on using the changeset viewer.