Last active
August 29, 2015 14:08
-
-
Save jrobinsonc/8dcfb3280d93345d7ff4 to your computer and use it in GitHub Desktop.
Wordpress helper: Get file URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* get_file_url | |
* | |
* Usage example: | |
* | |
* URL relative to the base file: | |
* get_file_url('styles.css', __FILE__); | |
* | |
* Or | |
* | |
* URL relative to the theme: | |
* get_file_url('css/styles.css'); | |
* | |
* @author JoseRobinson.com | |
* @link https://gist.github.com/jrobinsonc/8dcfb3280d93345d7ff4 | |
*/ | |
function get_file_url($file_name, $base_file = '') | |
{ | |
// URL relative to the theme. | |
if ($base_file === '') | |
return get_template_directory_uri() . "/{$file_name}"; | |
// URL relative to the base file. | |
else | |
return str_replace(get_template_directory(), get_template_directory_uri(), dirname($base_file) . '/' . $file_name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment