Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrobinsonc/8dcfb3280d93345d7ff4 to your computer and use it in GitHub Desktop.
Save jrobinsonc/8dcfb3280d93345d7ff4 to your computer and use it in GitHub Desktop.
Wordpress helper: Get file URL
<?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