[wp-trac] [WordPress Trac] #18302: Improve child theme file inheritance by introducing a function to locate a file URI

WordPress Trac wp-trac at lists.automattic.com
Sun Jul 31 01:19:02 UTC 2011


#18302: Improve child theme file inheritance by introducing a function to locate a
file URI
-------------------------+-----------------------------
 Reporter:  johnbillion  |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Template     |    Version:
 Severity:  normal       |   Keywords:  needs-patch
-------------------------+-----------------------------
 Child theme file inheritance isn't quite as slick as it could be. A child
 theme should be able to selectively override any of its parent theme's
 files (ie. CSS & JS), not just template files.

 For example, there's no easy way for a parent theme to enqueue a
 JavaScript file that can be easily overridden by a child theme. This is
 because there's no URI version of `locate_template()` for themes to use.

 Example: A parent theme includes a JavaScript file like so:

 {{{
 wp_enqueue_script( 'foo', get_template_directory_uri() . '/foo.js' );
 }}}

 A child theme couldn't simply include a `foo.js` file to override its
 parent's as the file is always loaded from the template directory, not the
 stylesheet directory. If the parent theme used
 `get_stylesheet_directory_uri()` instead, then the child theme could
 override it '''but''' it would '''have''' to override it, otherwise we'd
 end up with a file not found.

 The answer is to introduce a function that does the same as
 `locate_template()` but returns a URI instead of a path.

 Example usage:

 {{{
 wp_enqueue_script( 'foo', locate_theme_file( 'foo.js' ) );
 }}}

 This would load `foo.js` from the child theme if it existed, and the
 parent theme if not.

 The function could also be used for CSS files:

 {{{
 wp_enqueue_style( 'bar', locate_theme_file( 'bar.css' ) );
 }}}

 And for images too:

 {{{
 <img src="<?php echo locate_theme_file( 'icon.png' ); ?>" />
 }}}

 Stand by for a patch.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18302>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list