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

WordPress Trac noreply at wordpress.org
Thu Mar 7 02:47:40 UTC 2013


#18302: Improve child theme file inheritance by introducing `theme_url()` to locate
a file URI
-------------------------------------------------+-------------------------
 Reporter:  johnbillion                          |       Owner:  westi
     Type:  enhancement                          |      Status:  reviewing
 Priority:  normal                               |   Milestone:  Future
Component:  Template                             |  Release
 Severity:  normal                               |     Version:
 Keywords:  has-patch westi-likes needs-unit-    |  Resolution:
  tests                                          |
-------------------------------------------------+-------------------------

Comment (by greenshady):

 This should be simple.  Here's the code I've been using, which works fine.
 From here:
 https://github.com/justintadlock/hybrid-
 core/blob/1.5/functions/utility.php#L224

 {{{
 function hybrid_locate_theme_file( $file_names ) {

         $located = '';

         /* Loops through each of the given file names. */
         foreach ( (array) $file_names as $file ) {

                 /* If the file exists in the stylesheet (child theme)
 directory. */
                 if ( is_child_theme() && file_exists( trailingslashit(
 get_stylesheet_directory() ) . $file ) ) {
                         $located = trailingslashit(
 get_stylesheet_directory_uri() ) . $file;
                         break;
                 }

                 /* If the file exists in the template (parent theme)
 directory. */
                 elseif ( file_exists( trailingslashit(
 get_template_directory() ) . $file ) ) {
                         $located = trailingslashit(
 get_template_directory_uri() ) . $file;
                         break;
                 }
         }

         return $located;
 }
 }}}

 That's all we need.  Something simple that allows child themes to
 overwrite the file.

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


More information about the wp-trac mailing list