| | 2064 | * Retrieve the url of the highest priority template file that exists. |
| | 2065 | * |
| | 2066 | * Searches in the stylesheet directory before the template directory so themes |
| | 2067 | * which inherit from a parent theme can just overload one file. |
| | 2068 | * |
| | 2069 | * @since 3.5 |
| | 2070 | * |
| | 2071 | * @param string|array $template_names Template file(s) to search for, in order. |
| | 2072 | * @return string The URI of the file if one is located. |
| | 2073 | */ |
| | 2074 | function theme_url( $template_names, $else = null ) { |
| | 2075 | $url = $else; |
| | 2076 | $stylesheet_directory = trailingslashit( get_stylesheet_directory() ); |
| | 2077 | $template_directory = trailingslashit( get_template_directory() ); |
| | 2078 | $is_child_theme = ( $stylesheet_directory !== $template_directory ); |
| | 2079 | |
| | 2080 | foreach ( (array) $template_names as $template_name ) { |
| | 2081 | if ( ! $template_name = ltrim( $template_name, '/' ) ) |
| | 2082 | continue; |
| | 2083 | if ( $is_child_theme && file_exists( $stylesheet_directory . $template_name ) ) { |
| | 2084 | $url = trailingslashit( get_stylesheet_directory_uri() ) . $template_name; |
| | 2085 | break; |
| | 2086 | } elseif ( file_exists( $template_directory . $template_name ) ) { |
| | 2087 | $url = trailingslashit( get_template_directory_uri() ) . $template_name; |
| | 2088 | break; |
| | 2089 | } |
| | 2090 | } |
| | 2091 | |
| | 2092 | if( empty( $url ) && ! empty( $template_name ) ) |
| | 2093 | $url = trailingslashit( get_template_directory_uri() ) . $template_name; |
| | 2094 | |
| | 2095 | return apply_filters( 'theme_url', $url, $template_names, $else ); |
| | 2096 | } |
| | 2097 | |
| | 2098 | /** |