Skip to content

Instantly share code, notes, and snippets.

@drwpow
Created June 11, 2014 19:01
Show Gist options
  • Save drwpow/fce83a7e6a822379aca3 to your computer and use it in GitHub Desktop.
Save drwpow/fce83a7e6a822379aca3 to your computer and use it in GitHub Desktop.
//----- functions.php -----//
$site_url = get_bloginfo('url');
$template_url = get_bloginfo('template_directory');
//----- index.php (or wherever) -----//
<?php
global $site_url;
global $template_url;
?>
<img src="<?= $template_url ?>/img/myimage.jpg">
@drwpow
Copy link
Author

drwpow commented Jun 11, 2014

You have to declare global $template_url; in a PHP block near the top in whatever template you want to use this variable.

@drwpow
Copy link
Author

drwpow commented Jun 11, 2014

You could just run get_bloginfo('template_directory') whenever you wanted to grab the template path, but your DB queries will skyrocket if you do that several times on the page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment