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 Oct 20, 2021
1 parent 3a2fe6d commit 4a88f70
Showing 1 changed file with 21 additions and 51 deletions.
72 changes: 21 additions & 51 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,27 @@ function twentytwentytwo_support() {
add_action( 'after_setup_theme', 'twentytwentytwo_support' );
endif;

if ( ! function_exists( 'twentytwentytwo_styles' ) ) :
/**
* Enqueue scripts and styles.
*/
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() );
// Enqueue theme stylesheet.
wp_style_add_data( 'twentytwentytwo-style', 'path', get_template_directory() . '/style.css' );
wp_enqueue_style( 'twentytwentytwo-style' );
}
add_action( 'wp_enqueue_scripts', 'twentytwentytwo_styles' );
endif;

if ( ! function_exists( 'twentytwentytwo_editor_styles' ) ) :
/**
* Enqueue editor styles.
*/
function twentytwentytwo_editor_styles() {
wp_add_inline_style( 'wp-block-library', twentytwentytwo_get_font_face_styles() );
}
add_action( 'admin_init', 'twentytwentytwo_editor_styles' );
endif;

if ( ! function_exists( 'twentytwentytwo_get_font_face_styles' ) ) :
/**
* Get font face styles.
*
* @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/source-serif-pro/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/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2' ) . "') format('woff2');
}
";
}
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;

// Add block patterns
Expand Down

0 comments on commit 4a88f70

Please sign in to comment.