[wp-trac] [WordPress Trac] #39481: Twenty Seventeen: Allowing Google fonts in child themes

WordPress Trac noreply at wordpress.org
Fri Jan 6 07:39:40 UTC 2017


#39481: Twenty Seventeen: Allowing Google fonts in child themes
---------------------------+------------------------------
 Reporter:  tsvikas        |       Owner:
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Bundled Theme  |     Version:
 Severity:  normal         |  Resolution:
 Keywords:  has-patch      |     Focuses:
---------------------------+------------------------------

Comment (by superpoincare):

 There are complications in dequeuing parent fonts in bundled themes. This
 is because they sometimes add a body class (such as twenty twelve) and all
 add a ''preconnect'' hint.

 So dequeuing implies one has to add the body class again and also write
 code for preconnect.

 This is how I do it in the child theme:


 {{{
 function twentytwelve_child_get_font_url( $src, $handle ) {
         if ( 'twentytwelve-fonts' === $handle ) {
                 return str_replace( array( 'twentytwelve-fonts', 'latin
 ,latin-ext' ), array( 'twentytwelve-child-fonts', 'latin,latin-ext,greek
 ,greek-ext' ), $src );
         }
         return $src;
 }
 add_filter( 'style_loader_tag', 'twentytwelve_child_get_font_url', 10, 2
 );
 }}}

 Making the functions in the parent theme pluggable has potential side
 effects. Suppose I change the font url in the child theme by overriding
 the hypothetical pluggable function with another font-service. The html
 output will still have the preconnect hints and a body class (in some
 themes).

 This is because the code for preconnect and body class check to see if the
 font handle is in queue.

 Hence the best way of modifying is by using '''style_loader_tag'''

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


More information about the wp-trac mailing list