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

I'm creating a twitter bootstrapped child theme based on TwentyEleven.I want to load bootstrap.js so I've written the following line to get the bootstrap.js file but it is not returning correct path.

<script type="text/javascript" src="<?php dirname( bloginfo('stylesheet_url') ) ?>/bootstrap/js/bootstrap.js"></script>

The path I'm getting:


The path I should get:

share|improve this question
up vote 4 down vote accepted

The reason why your code isn't working is because bloginfo() echoes the data where get_bloginfo() doesn't. So dirname() isn't really used. Using stylesheet_directory is better though since that won't need the dirname() call at all.

You could also use the wrapper get_stylesheet_directory_uri() which adheres to the filter stylesheet_directory_uri.

This is your code corrected:

<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/bootstrap/js/bootstrap.js"></script>

See: http://codex.wordpress.org/Function_Reference/bloginfo

However, the "WordPress-way" of adding scripts is by adding it the script queue. Doing it this way will ensure that your script is always loaded after it's dependencies and it will also make it possible for other scripts to use your script as a dependency.

To add a script to WordPress's queue you use wp_enqueue_script(). See the examples. Below is a script which should work for you. Add it to your theme's functions.php file.

function enqueue_bootstrap() {
  wp_enqueue_script('twitter-bootstrap', get_stylesheet_directory_uri() . '/bootstrap/js/bootstrap.js', array('jquery'));
add_action('wp_enqueue_scripts', 'enqueue_bootstrap');
share|improve this answer
Sorry, but that's a bad advice in so many directions... – kaiser Sep 19 '12 at 12:31
In what way? As I understood it, he asked what he did wrong. Sure he should use wp_enqueue_script(), but that wasn't really the question. – hampusn Sep 19 '12 at 12:33
Then simply show him how to make it better. – kaiser Sep 19 '12 at 12:35
I'm a Wordpress newbie so can you tell where I should put that enqueue function? – Rajat Saxena Sep 19 '12 at 12:47
@kaiser Updated. Overall betterified answer. – hampusn Sep 19 '12 at 13:06

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.