WordPress CMS modifications

Making WordPress more like a CMS everyday!





Dynamically generating the file path to the template directory

Last Modified: 24 July, 2008 (17:27) | First Created: 18 April, 2008
Posted In: Template Development | Written by: Jonny

When you start getting deeper into WordPress theme development, you will often have to reference images, includes and other files. To keep things tidy, you should keep all of these in the template folder. Then you can move your theme around different blogs and websites and all the paths will work.

You simply need the piece of code:

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

This will generate the url to the current template folder dynamically through WordPress. For instance, you may have included some Javascript in your theme, and it’s convenient to keep this all together in a folder called ‘jscript’ within your template directory. Rather than have to hard-code the URL path in your template file, like ‘www.mysite.com/wp-content/themes/mytheme/jscript/script1.js’ you would write this as:

<?php bloginfo('template_directory'); ?>/jscript/script1.js


Write a comment