2

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.

2 Answers 2

3

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' );
1
  • 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. Commented Dec 9, 2011 at 17:02
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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