Make WordPress Core


Ignore:
Timestamp:
04/26/2022 03:25:01 PM (4 years ago)
Author:
jffng
Message:

Twenty Twenty-Two: Add three style variations.

This commit adds three style variations to Twenty Twenty-Two, allowing users to quickly swap between different visual styles — "Blue", "Pink", and "Swiss" — for the default theme. The variations are previewed and selected from the Site Editor's global styles panel.

For the implementation, each variation is defined by its own theme.json file within the "/styles" directory of the theme. All variations leverage the internal-only theme.json handler of the Webfonts API [53282] to load locally hosted fonts.

Props kjellr, hellofromtonya.
See #55433.

File:
1 edited

Legend:

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

    r52392 r53286  
    5555        );
    5656
    57         // Add styles inline.
    58         wp_add_inline_style( 'twentytwentytwo-style', twentytwentytwo_get_font_face_styles() );
    59 
    6057        // Enqueue theme stylesheet.
    6158        wp_enqueue_style( 'twentytwentytwo-style' );
     
    6764add_action( 'wp_enqueue_scripts', 'twentytwentytwo_styles' );
    6865
    69 if ( ! function_exists( 'twentytwentytwo_editor_styles' ) ) :
    70 
    71     /**
    72      * Enqueue editor styles.
    73      *
    74      * @since Twenty Twenty-Two 1.0
    75      *
    76      * @return void
    77      */
    78     function twentytwentytwo_editor_styles() {
    79 
    80         // Add styles inline.
    81         wp_add_inline_style( 'wp-block-library', twentytwentytwo_get_font_face_styles() );
    82 
    83     }
    84 
    85 endif;
    86 
    87 add_action( 'admin_init', 'twentytwentytwo_editor_styles' );
    88 
    89 
    90 if ( ! function_exists( 'twentytwentytwo_get_font_face_styles' ) ) :
    91 
    92     /**
    93      * Get font face styles.
    94      * Called by functions twentytwentytwo_styles() and twentytwentytwo_editor_styles() above.
    95      *
    96      * @since Twenty Twenty-Two 1.0
    97      *
    98      * @return string
    99      */
    100     function twentytwentytwo_get_font_face_styles() {
    101 
    102         return "
    103         @font-face{
    104             font-family: 'Source Serif Pro';
    105             font-weight: 200 900;
    106             font-style: normal;
    107             font-stretch: normal;
    108             font-display: swap;
    109             src: url('" . get_theme_file_uri( 'assets/fonts/SourceSerif4Variable-Roman.ttf.woff2' ) . "') format('woff2');
    110         }
    111 
    112         @font-face{
    113             font-family: 'Source Serif Pro';
    114             font-weight: 200 900;
    115             font-style: italic;
    116             font-stretch: normal;
    117             font-display: swap;
    118             src: url('" . get_theme_file_uri( 'assets/fonts/SourceSerif4Variable-Italic.ttf.woff2' ) . "') format('woff2');
    119         }
    120         ";
    121 
    122     }
    123 
    124 endif;
    125 
    126 if ( ! function_exists( 'twentytwentytwo_preload_webfonts' ) ) :
    127 
    128     /**
    129      * Preloads the main web font to improve performance.
    130      *
    131      * Only the main web font (font-style: normal) is preloaded here since that font is always relevant (it is used
    132      * on every heading, for example). The other font is only needed if there is any applicable content in italic style,
    133      * and therefore preloading it would in most cases regress performance when that font would otherwise not be loaded
    134      * at all.
    135      *
    136      * @since Twenty Twenty-Two 1.0
    137      *
    138      * @return void
    139      */
    140     function twentytwentytwo_preload_webfonts() {
    141         ?>
    142         <link rel="preload" href="<?php echo esc_url( get_theme_file_uri( 'assets/fonts/SourceSerif4Variable-Roman.ttf.woff2' ) ); ?>" as="font" type="font/woff2" crossorigin>
    143         <?php
    144     }
    145 
    146 endif;
    147 
    148 add_action( 'wp_head', 'twentytwentytwo_preload_webfonts' );
    149 
    15066// Add block patterns
    15167require get_template_directory() . '/inc/block-patterns.php';
Note: See TracChangeset for help on using the changeset viewer.