Opened 9 years ago
Closed 9 years ago
#36592 closed defect (bug) (worksforme)
enqueue child theme with parent resource dependency and version shows child version
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | |
Focuses: | template | Cc: |
Description
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:
$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:
$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
Hello @Twintails, welcome to our Trac!
wp_get_theme()
falls back toget_stylesheet()
if the first argument isn't set.get_stylesheet()
returns in this case the value for the child theme. You have to passget_template()
towp_get_theme()
to get the theme object of the parent theme: