f64049821c2d4874b99196b47db9cee7

How to Link to the Root Directory of a WordPress Theme

Written by on December 12, 2011 in WordPress - No comments
wordpress-theme

When coding a WordPress theme you’re obviously going to need to link scripts to your theme files. If you were going to link directly a file it would look something like this:

<script src='http://mydomain.com/wp-content/themes/mytheme/js/slider.js'></script>

Luckily there is a quicker way to link directly to these files. The following PHP snippet links directly to the root of your theme:

<?php bloginfo('template_directory'); ?>

So to link to the same example file as above you would do this:

<script src='<?php bloginfo('template_directory'); ?>/js/slider.js'></script>

This is obviously easier, less code, and if you move your WordPress install or change the theme name the link will still be correct.