[wp-trac] [WordPress Trac] #36592: enqueue child theme with parent resource dependency and version shows child version

WordPress Trac noreply at wordpress.org
Tue Apr 19 13:33:27 UTC 2016


#36592: enqueue child theme with parent resource dependency and version shows child
version
--------------------------+-----------------------------
 Reporter:  Twintails     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Themes        |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:  template      |
--------------------------+-----------------------------
 When you have wp_register_script or wp_register_style in the Parent theme
 functions and then use these $handles as dependencies for proper load
 order and overrides in the Child theme functions.


 '''EXAMPLE 1:'''
 {{{#!php
 $the_parent_theme = wp_get_theme();
  wp_register_style( 'my-parent-style', get_template_directory_uri() .
 '/path/to/style.css', array( '' ), $the_parent_theme->get( 'Version' ),
 true );
 }}}

 should and does output:

 {{{
 <link rel="stylesheet" id="my-parent-style-css" href="http://domain/wp-
 content/themes/my-parent-theme/path/to/style.css?ver=candy-1.3"
 type="text/css" media="all">
 }}}


 Then in the child functions you call the parent $handle in the $deps[] for
 the Child to ensure they load first. And the Child has a version Number
 set with 'x.x.x' or $the_child_theme->get( 'Version' )

 '''EXAMPLE 2:'''
 {{{#!php
 $the_child_theme = wp_get_theme();
  wp_register_style( 'my-child-style', get_stylesheet_directory_uri() .
 '/path/to/style.css', array( 'my-parent-style' ), $the_child_theme->get(
 'Version' ), true );
 }}}

 ----

 '''ACTUAL RESULT:'''

 {{{
 <link rel="stylesheet" id="my-parent-style-css" href="http://sub.domain
 /wp-content/themes/my-parent-theme/path/to/style.css?ver=kiddo1"
 type="text/css" media="all">
 <link rel="stylesheet" id="my-child-style-css" href="http://sub.domain/wp-
 content/themes/mi-child-theme/path/to/style.css?ver=kiddo1"
 type="text/css" media="all">
 }}}


 The script or link src output for both the parent and the child is to
 include the child version number. This is incorrect and should display the
 child version number on the child files only.
 The parent version should not be overridden and should display if those
 files are registered with their own version.

 ----

 '''EXPECTED RESULT:'''
 {{{
 <link rel="stylesheet" id="my-parent-style-css" href="http://sub.domain
 /wp-content/themes/my-parent-theme/path/to/style.css?ver=candy-1.3"
 type="text/css" media="all">
 <link rel="stylesheet" id="my-child-style-css" href="http://sub.domain/wp-
 content/themes/my-child-theme/path/to/style.css?ver=kiddo1"
 type="text/css" media="all">
 }}}


 ----
 '''WORKAROUND:'''
 A developer can de-register and re-register the parent style/script with
 the template version in the child theme functions, but that seems like
 excess and wasteful code and goes against the DRY approach.

 If the parent is registering the files, the child should not need to. All
 the child should have is to call the handle of the parent file as a
 dependency and the returned array should append the parent version to the
 parent src.

 '''TESTED IN'''
 4.4.2, 4.5

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36592>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list