From ed1c480c173f64787f24ada471d40221dd697e83 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 7 Oct 2021 13:22:19 +0300 Subject: [PATCH 1/2] Fix font paths --- functions.php | 28 ++++++++++++++++++++++++---- style.css | 33 --------------------------------- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/functions.php b/functions.php index 69528f90..42918057 100644 --- a/functions.php +++ b/functions.php @@ -20,10 +20,30 @@ function twentytwentytwo_support() { * Enqueue scripts and styles. */ function twentytwentytwo_styles() { + // The @font-face styles. + $font_face_css = " + @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'); + } + "; + // Register theme stylesheet. + wp_register_style( 'twentytwentytwo-style', '' ); + // Add styles inline. + wp_add_inline_style( 'twentytwentytwo-style', $font_face_css ); // Enqueue theme stylesheet. - $theme_version = wp_get_theme()->get( 'Version' ); - $version_string = is_string( $theme_version ) ? $theme_version : false; - wp_enqueue_style( 'twentytwentytwo-style', get_template_directory_uri() . '/style.css', array(), $version_string ); + wp_enqueue_style( 'twentytwentytwo-style' ); } add_action( 'wp_enqueue_scripts', 'twentytwentytwo_styles' ); endif; @@ -41,4 +61,4 @@ function twentytwentytwo_editor_styles() { ); } add_action( 'admin_init', 'twentytwentytwo_editor_styles' ); -endif; \ No newline at end of file +endif; diff --git a/style.css b/style.css index e387e913..325321d7 100644 --- a/style.css +++ b/style.css @@ -14,36 +14,3 @@ Text Domain: twentytwentytwo Twenty Twenty-Two WordPress Theme, (C) 2021 WordPress.org Twenty Twenty-Two is distributed under the terms of the GNU GPL. */ - -/*-------------------------------------------------------------- - >>> TABLE OF CONTENTS: - ---------------------------------------------------------------- - - 0. Fonts - - ----------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* 0. Fonts -/* -------------------------------------------------------------------------- */ - -/* - * Fonts can be reworked if this core issue is resolved: - * https://github.com/WordPress/wordpress-develop/pull/1573 - */ - -@font-face{ - font-family: 'Source Serif Pro'; - font-weight: 200 900; - font-style: normal; - font-stretch: normal; - src: url('/wp-content/themes/twentytwentytwo/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('/wp-content/themes/twentytwentytwo/assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2') format('woff2'); -} From 025d393afabfd30a0380ef915f963933396369bf Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 8 Oct 2021 11:28:26 +0300 Subject: [PATCH 2/2] make styles work in the editor --- functions.php | 52 +++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/functions.php b/functions.php index 42918057..98fb27c3 100644 --- a/functions.php +++ b/functions.php @@ -20,8 +20,34 @@ function twentytwentytwo_support() { * Enqueue scripts and styles. */ function twentytwentytwo_styles() { - // The @font-face styles. - $font_face_css = " + // 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_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; @@ -38,27 +64,5 @@ function twentytwentytwo_styles() { src: url('" . get_theme_file_uri( 'assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2' ) . "') format('woff2'); } "; - // Register theme stylesheet. - wp_register_style( 'twentytwentytwo-style', '' ); - // Add styles inline. - wp_add_inline_style( 'twentytwentytwo-style', $font_face_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. - */ - function twentytwentytwo_editor_styles() { - // Enqueue editor styles. - add_editor_style( - array( - get_stylesheet_uri(), - ) - ); - } - add_action( 'admin_init', 'twentytwentytwo_editor_styles' ); endif;