Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Implement the webfonts API
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Nov 4, 2021
1 parent 244586b commit 7f562c5
Showing 1 changed file with 21 additions and 77 deletions.
98 changes: 21 additions & 77 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,84 +29,28 @@ function twentytwentytwo_support() {

endif;


if ( ! function_exists( 'twentytwentytwo_styles' ) ) :

/**
* Enqueue styles.
*
* @return void
*/
function twentytwentytwo_styles() {

// Register theme stylesheet.
wp_register_style( 'twentytwentytwo-style', '' );

// Add styles inline.
wp_add_inline_style( 'twentytwentytwo-style', twentytwentytwo_get_font_face_styles() );

// Add metadata to the CSS stylesheet.
wp_style_add_data( 'twentytwentytwo-style', 'path', get_template_directory() . '/style.css' );

// Enqueue theme stylesheet.
wp_enqueue_style( 'twentytwentytwo-style' );

}
add_action( 'wp_enqueue_scripts', 'twentytwentytwo_styles' );

endif;


if ( ! function_exists( 'twentytwentytwo_editor_styles' ) ) :

/**
* Enqueue editor styles.
*
* @return void
*/
function twentytwentytwo_editor_styles() {

// Add styles inline.
wp_add_inline_style( 'wp-block-library', twentytwentytwo_get_font_face_styles() );

}
add_action( 'admin_init', 'twentytwentytwo_editor_styles' );

if ( function_exists( 'wp_register_webfonts' ) ) :
wp_register_webfonts(
array(
array(
'fontFamily' => 'Source Serif Pro',
'fontWeight' => '200 900',
'fontStyle' => 'normal',
'fontStretch' => 'normal',
'src' => get_theme_file_uri( 'assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2' ),
'provider' => 'local',
),
array(
'fontFamily' => 'Source Serif Pro',
'fontWeight' => '200 900',
'fontStyle' => 'italic',
'fontStretch' => 'normal',
'src' => get_theme_file_uri( 'assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2' ),
'provider' => 'local',
),
)
);
endif;


if ( ! function_exists( 'twentytwentytwo_get_font_face_styles' ) ) :

/**
* Get font face styles.
* Called by functions twentytwentytwo_styles() and twentytwentytwo_editor_styles() above.
*
* @return string
*/
function twentytwentytwo_get_font_face_styles() {

return "
@font-face{
font-family: 'Source Serif Pro';
font-weight: 200 900;
font-style: normal;
font-stretch: normal;
src: url('" . get_theme_file_uri( 'assets/fonts/SourceSerif4Variable-Roman.ttf.woff2' ) . "') format('woff2');
}
@font-face{
font-family: 'Source Serif Pro';
font-weight: 200 900;
font-style: italic;
font-stretch: normal;
src: url('" . get_theme_file_uri( 'assets/fonts/SourceSerif4Variable-Italic.ttf.woff2' ) . "') format('woff2');
}
";

}

endif;


// Add block patterns
require get_template_directory() . '/inc/block-patterns.php';

0 comments on commit 7f562c5

Please sign in to comment.