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.

All my enqueued styles are applied to the back-end as well. I have never encountered this behavior before.

Here's my code:

wp_register_style( 'main-styles', get_stylesheet_directory_uri() . '/css/styles.css', false, '1.0.0', 'all');

wp_enqueue_style('main-styles');
share|improve this question
    
what action do you add these on? –  Milo Feb 7 '13 at 18:11

2 Answers 2

up vote 5 down vote accepted

Why are my styles being applied to the admin area?

Assuming that is all of the code, it is because you are enqueueing the styles globally. You need to hook that to wp_enqueue_scripts, which will only load on the front end.

wp_register_style( 'main-styles', get_stylesheet_directory_uri() . '/css/styles.css', false, '1.0.0', 'all');

function enqueue_script_front_wpse_84975() {
  wp_enqueue_style('main-styles');
}
add_action('wp_enqueue_scripts', 'enqueue_script_front_wpse_84975');

You can register globally or put that wp_register_scripts part inside the enqueue_script_front_wpse_84975 function, but you need to hook wp_enqueue_style, at least, to wp_enqueue_scripts or you will enqueue the stylesheet everywhere. I realize it seems weird to enqueue a stylesheet on a hook ending in "script" but that is correct per the Codex.

wp_enqueue_style can be, and is, used to enqueue anywhere, front or back end, as you can see on the Codex page for admin_enqueue_scripts

share|improve this answer

Where are you hooking these?

If you look at the codex, you should add these to a function and hook the function to wp_enqueue_scripts for front end display.

Example:

function add_my_css(){
wp_register_style( 'main-styles', get_stylesheet_directory_uri() . '/css/styles.css', false, '1.0.0', 'all');

wp_enqueue_style('main-styles');
}

add_action('wp_enqueue_scripts', 'add_my_css');
share|improve this answer

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.