Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm having trouble getting the second argument in wp_enque_style. Here's how my site is setup:

  • style.css
  • custom_style.css
  • index.php

In a template, I have this code:

$stylesheet_url = bloginfo('template_directory') . '/custom_style.css'; 
wp_enqueue_style( 'custom_style', $stylesheet_url ); 

Which isn't working. Any reasons why?

The output is just the path to my template directory, outputted as raw text, which is obviously not the correct behavior.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

To enqueue extra styles you should place the following code in your functions.php

function my_custom_styles() {
    wp_enqueue_style( 'custom-style', get_stylesheet_directory_uri() . '/custom_style.css');
}
add_action( 'wp_print_styles', 'my_custom_styles' );
share|improve this answer
1  
To clarify: get_template_directory() (along with the OP's use of get_bloginfo( 'template_directory' )) returns the file path to the template directory. For publicly accessible resources (such as enqueued scripts/stylesheets), you need to use the template directory URL, which is returned by get_template_directory_uri() - and which this answer demonstrates. –  Chip Bennett Dec 9 '11 at 17:02
add comment

use get_bloginfo instead, which returns the value instead of directly echoing it.

share|improve this answer
add comment

Your Answer

 
discard

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.