[wp-trac] [WordPress Trac] #39323: Twenty Seventeen: wp_resource_hints when enqueue custom fonts in child theme

WordPress Trac noreply at wordpress.org
Fri Dec 30 21:26:13 UTC 2016


#39323: Twenty Seventeen: wp_resource_hints when enqueue custom fonts in child
theme
---------------------------+-----------------------
 Reporter:  sami.keijonen  |       Owner:
     Type:  enhancement    |      Status:  reopened
 Priority:  normal         |   Milestone:
Component:  Bundled Theme  |     Version:  4.7
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:
---------------------------+-----------------------
Changes (by sami.keijonen):

 * status:  closed => reopened
 * resolution:  wontfix =>


Comment:

 I'm not giving up for two reasons:)

 - It feels so odd and wrong to duplicate the same function in a child
 theme.
 - This is an example why filters are better approach than pluggable
 function (not that this is).

 So why not add a filter around fonts handle  like this:


 {{{
 function twentyseventeen_resource_hints( $urls, $relation_type ) {
         // Fonts handle which we can filter in child theme.
         $fonts_handle = apply_filters(
 'twentyseventeen_preconnect_fonts_handle', 'twentyseventeen-fonts' );

         if ( wp_style_is( esc_attr( $fonts_handle ), 'queue' ) &&
 'preconnect' === $relation_type ) {
                 $urls[] = array(
                         'href' => 'https://fonts.gstatic.com',
                         'crossorigin',
                 );
         }

         return $urls;
 }
 add_filter( 'wp_resource_hints', 'twentyseventeen_resource_hints', 10, 2
 );
 }}}

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


More information about the wp-trac mailing list