| 2432 | |
| 2433 | /** |
| 2434 | * Retrieve the url of a file in the theme. |
| 2435 | * |
| 2436 | * Searches in the stylesheet directory before the template directory so themes |
| 2437 | * which inherit from a parent theme can just override one file. |
| 2438 | * |
| 2439 | * @since 3.5.0 |
| 2440 | * |
| 2441 | * @param string $file File to search for in the stylesheet directory. |
| 2442 | * @return string The URL of the file. |
| 2443 | */ |
| 2444 | function theme_url( $file = '' ) { |
| 2445 | $file = ltrim( $file, '/' ); |
| 2446 | |
| 2447 | if ( empty( $file ) ) { |
| 2448 | $url = get_stylesheet_directory_uri(); |
| 2449 | } elseif( is_child_theme() && file_exists( get_stylesheet_directory() . "/$file" ) { |
| 2450 | $url = get_stylesheet_directory_uri() . "/$file"; |
| 2451 | } else { |
| 2452 | $url = get_template_directory_uri() . "/$file"; |
| 2453 | } |
| 2454 | |
| 2455 | return apply_filters( 'theme_url', $url, $file ); |
| 2456 | } |
| 2457 | |
| 2458 | /** |
| 2459 | * Retrieve the url of a file in the parent theme. |
| 2460 | * |
| 2461 | * @since 3.5.0 |
| 2462 | * |
| 2463 | * @param string $file File to return the url for in the template directory. |
| 2464 | * @return string The URL of the file. |
| 2465 | */ |
| 2466 | function parent_theme_url( $file = '' ) { |
| 2467 | $file = ltrim( $file, '/' ); |
| 2468 | |
| 2469 | if ( empty( $file ) ) { |
| 2470 | $url = get_template_directory_uri(); |
| 2471 | } else { |
| 2472 | $url = get_template_directory_uri() . "/$file"; |
| 2473 | } |
| 2474 | |
| 2475 | return apply_filters( 'parent_theme_url', $url, $file ); |
| 2476 | } |