Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#36592 closed defect (bug) (worksforme)

enqueue child theme with parent resource dependency and version shows child version

Reported by: twintails's profile Twintails Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords:
Focuses: template Cc:


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.


$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' )


$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 );


<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.


<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">

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.

4.4.2, 4.5

Change History (2)

#1 @SergeyBiryukov
8 years ago

  • Component changed from Themes to Script Loader

#2 @ocean90
8 years ago

  • Component changed from Script Loader to Themes
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
  • Version trunk deleted

Hello @Twintails, welcome to our Trac!

wp_get_theme() falls back to get_stylesheet() if the first argument isn't set. get_stylesheet() returns in this case the value for the child theme. You have to pass get_template() to wp_get_theme() to get the theme object of the parent theme:

$the_parent_theme = wp_get_theme( get_template() );
wp_register_style( 'my-parent-style', get_template_directory_uri() . '/path/to/style.css', array(), $the_parent_theme->get( 'Version' ), true );

$the_child_theme = wp_get_theme( get_stylesheet() );
wp_register_style( 'my-child-style', get_stylesheet_directory_uri() . '/path/to/style.css', array( 'my-parent-style' ), $the_child_theme->get( 'Version' ), true );
Note: See TracTickets for help on using tickets.