WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In WordPress, I've been installing and using various themes, including 2013, Roots, and now BlankSlate. I noticed that now that I've activated BlankSlate, the function get_template_directory() used in front-page.php is still returning the path to the Roots theme directory. My current front-page.php looks like this.

<?php get_header(); ?>
<section id="content" role="main">
       <img class="frontpageimg" src="<?php get_template_directory(); ?>/images/slogan-2.png">

       <h4>In the Los Angeles area? </h4> <p>Ask about free demo loaners! </p>
       <h4>We also take mail orders.</h4> On all orders, there is a 30-day return policy!</p> 

       <img src = "<?php get_template_directory(); ?>/assets/img/cables-ers-absorber-700.jpg"/></a>
       <img src = "<?php get_template_directory(); ?>/assets/img/blueprint-silencers-v2-700.jpg"/></a>
       <img src = "<?php get_template_directory(); ?>/assets/img/brav-front-page-700.jpg"/></a>

        <a href="contact" class="btn btn-lg btn-orange">Contact Us</a>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

EDIT UPDATE: Did some some debugging as follows:

Deactivated all plugins. Logged out, cleared cache. The problem persisted.

Switched from BlankSlate (in which the problem was evident) to 2013 theme. Similar behavior, although I now can say more specifically what that behavior is. While in the 2013 theme, apparently the PHP construct <?php echo get_template_directory(); ?>/path-in-2013-theme/file.jpg works, but <?php get_template_directory(); ?> returns the path to the Roots theme. The same is true of <?php echo get_template_directory_uri(); ?> (works correctly with the echo but not without).

However, the behavior is somewhat different in BlankSlate. Without the echo both get_template_directory() and get_template_directory_uri() return the path to Roots theme, while with the echo they do something else (but I'm not sure what that something else is.. how do I dump these values for debugging?)


I was able to inspect the page source with Firebug. Sure enough, the functions had no output without echo. So the image source was src="/assets/img/brav-banner-3.jpg and so forth. And that worked in some themes. I mean I could see the image. So maybe it's a caching problem? When I added the echo and changed the path to the jpg, I was able to get it to work in the BlankSlate theme. So I am going to mark this solved, as a caching issue.

share|improve this question
Try logging out, cleaning cache of your browser and then logging in. If that still doesn't work, I think you should post more details about your setup; it sounds as if an error occurred while you were switching the themes. – Aram Boyajyan Oct 24 '13 at 6:43
I checked out the theme BlankSlate and in the default package where was no such a file as front-page.php. Have you made it yourself? From your post is not entirely clear what a theme you have activated, whether you have customized it. And the last thing, when you use get_template_directory, it returns an absolute path, which you would use, when including/requiring files, for loading stuff from your theme folder to public, like CSS, IMGs, JSs, use get_template_directory_uri – Ivan Hanák Oct 24 '13 at 6:54
Please do basic troubleshooting. Do you have any Plugins active? Does the problem persist with all Plugins disabled? Does this happen only with the Blank Slate Theme, or does it happen with a core-bundled Theme (such as Twenty Twelve or Twenty Thirteen)? If the problem persists with a core-bundled Theme active, then the problem is probably with something the Roots Theme did. In that case, try a clean install of WordPress, with no Plugins active. – Chip Bennett Oct 24 '13 at 12:59
P.S. Roots Theme screws with relative URLs and rewrites. Try flushing your rewrite rules, and see if that helps. – Chip Bennett Oct 24 '13 at 13:06
Thanks, everyone. I will proceed with debugging. Ivan, your last sentence is hard to decipher... can you try rewriting it? I think you are saying I should switch to get_template_directory_uri. I did add front-page.php myself. – composerMike Oct 24 '13 at 20:33
up vote 0 down vote accepted

The get_template_directory() and get_template_directory_uri() functions don't actually echo anything at all. They will make no output at all unless you echo them.

So your code that looks like this:

<img class="frontpageimg" src="<?php get_template_directory(); ?>/images/slogan-2.png">

Should actually cause this output:

<img class="frontpageimg" src="/images/slogan-2.png">

Which may not be what you're expecting. Examine the source of the page. And add that echo, it's not optional. :)

Also, if the theme may have screwed with relative urls and rewrites and such, as Chip suggests, then your browser is caching. Browser caching is notoriously difficult to debug. I like to use Chrome and the inspector tool, because when you have it open, right-clicking on the reload button gives you a "Empty Cache and Hard Reload" which does more what you expect it to do as far as showing the real truth of the matter.

share|improve this answer
I assure you it works without the echo in the Roots theme. Did Roots screw with these functions? – composerMike Oct 24 '13 at 21:48
When everything is preceded by or includes "in the Roots Theme", that is a pretty clear indication that the root cause of the issue is... the Roots Theme. – Chip Bennett Oct 24 '13 at 21:50
Well, it also works without the echo in 2013, just returning the path to the Roots assets directory. But before I install Chrome and try "hard reload" can someone tell me how to inspect the output of these functions directly, or look at the source code? Seems like a more direct approach. Oh, I did clear the cache in Firefox. EDIT: I just realized I can inspect the pages with Firebug. Doing that now. Will report back. – composerMike Oct 24 '13 at 22:03
See original question for further debugging info. Marked as solved (for now). – composerMike Oct 24 '13 at 22:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.