WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 have the following code in my functions.php file. It works, but I am wondering if this is best practice for including styles in wordpress. Also do I need to register the style with wp_reister_style, since it works without and why do I need to do so?

function mrskitson_load_styles(){
if (!is_admin()){
wp_register_style('main', get_template_directory_uri() . '/style.css');
wp_enqueue_style('main', get_template_directory_uri() . '/style.css');
}//if not admin ends
}//function mrskitson_load_styles ends
add_action('get_header', 'mrskitson_load_styles');
share|improve this question
up vote 2 down vote accepted

Two problems:

  1. You only need to provide the script path once, either in the wp_register_style() call, or in the wp_enqueue_style() call, but not both. (In fact, in this context, it would be fine to omit the wp_register_style() call entirely, and just use the wp_enqueue_style() call.)
  2. You're hooking into the wrong action. Try hooking into wp_enqueue_scripots instead of into get_header. (Note: this will require the Theme to include a call to <?php wp_head(); ?> in the document head - but it should be doing so, anyway.)

Other considerations:

  • For custom styles/scripts, I would recommend prefixing the style slug; e.g. change main to srskitson-main.
share|improve this answer

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.