[wp-trac] [WordPress Trac] #55985: [Twenty Twelve to Twenty Seventeen]: bundle Google Fonts in each theme

WordPress Trac noreply at wordpress.org
Mon Mar 6 12:02:20 UTC 2023


#55985: [Twenty Twelve to Twenty Seventeen]: bundle Google Fonts in each theme
-------------------------------------------------+-------------------------
 Reporter:  luminuu                              |       Owner:  audrasjb
     Type:  enhancement                          |      Status:  closed
 Priority:  high                                 |   Milestone:  6.2
Component:  Bundled Theme                        |     Version:
 Severity:  major                                |  Resolution:  fixed
 Keywords:  has-patch add-to-field-guide needs-  |     Focuses:  privacy
  dev-note                                       |
-------------------------------------------------+-------------------------

Comment (by sabernhardt):

 ==== Custom font stylesheet: fixing potential Classic Editor issues (if
 you cannot avoid them)

 1. The child theme’s stylesheet and directory should not match a file in
 its parent theme, or else the editor would fetch both stylesheets. For
 example, you could name yours `'/fonts/montserrat-all.css'` to avoid
 adding Twenty Sixteen’s `'/fonts/montserrat.css'`. If you ''already'' have
 a stylesheet with the same filename **and** directory, you could remove
 the extra file in the editor with a filter:
 {{{
 <?php
 function wpdocs_remove_parent_font_from_classic_editor( $mce_css ) {
         $font_url = str_replace(
                 get_stylesheet_directory_uri(),
                 get_template_directory_uri(),
                 twentysixteen_fonts_url()
         );
         $mce_css  = str_replace(
                 ',' . $font_url . ',',
                 ',',
                 $mce_css
         );

         return $mce_css;
 }
 add_filter( 'mce_css', 'wpdocs_remove_parent_font_from_classic_editor', 11
 );
 }}}

 2. If a query string such as a version number is important, the child
 theme function could add the variable only on the front end so that the
 Classic Editor still adds the fonts (without the query string):
 {{{
 <?php
 function twentysixteen_fonts_url() {
         $fonts_url = get_stylesheet_directory_uri() . '/fonts.css';
         if ( ! is_admin() ) {
                 $fonts_url = add_query_arg( 'ver', '1.1', $fonts_url );
         }
         return $fonts_url;
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55985#comment:115>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list