2

I have been using the following function to enqueue some CSS to my theme. However, they are used in the admin area as well:

wp_enqueue_style(...)

I don't want them to be used in the admin area. Sadly I cannot find anything about that neither here nor on Google in combination with this function. The codex doesn't explain it as well and the function does not support an option to apply to a specific style the exclusion of the admin area.

I hope somebody could tell me how to exclude a specific css from the admin area.

Thanks in advance.

3 Answers 3

5

There are a couple of options. One is to wrap the enqueue in a check to see if it is the admin.

if(!is_admin()) 
    wp_enqueue_style(....);

The other is wait to enqueue the style until template_redirect.

function my_enqueue_styles() {    
    wp_enqueue_style(....);
}
add_action( 'template_redirect', 'my_enqueue_styles' );
2
  • thanks, pretty much to everybody. I go with the highly recommended !is_admin(). Quite stupid that I didnt think of that - very easy : )
    – Richard
    Commented Feb 7, 2012 at 15:01
  • 2
    !is_admin is right, but theme review standards suggest all scripts and stylesheets should be added to the wp_enqueue_scripts hook Commented Feb 7, 2012 at 15:28
1

You can make your enquques conditional, for example: if( !is_admin() ) { wp_enquque_style( 'my_style' ) }. Any of the conditional tags will work in this way.

1

can you please show the exact code you're using?

If you are doing something like this:

wp_register_style('mycssname', "/wp-content/themes/[theme]/css/screen.css",array(),'false','screen');

you could do this:

if ( !is_admin() ) {
    wp_register_style('mycssname', "/wp-content/themes/[theme]/css/screen.css",array(),'false','screen');
}

.. or you might want to look at http://codex.wordpress.org/Function_Reference/wp_deregister_style

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.