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 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.

share|improve this question
add comment

3 Answers 3

up vote 2 down vote accepted

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' );
share|improve this answer
    
thanks, pretty much to everybody. I go with the highly recommended !is_admin(). Quite stupid that I didnt think of that - very easy : ) –  Richard Feb 7 '12 at 15:01
1  
!is_admin is right, but theme review standards suggest all scripts and stylesheets should be added to the wp_enqueue_scripts hook –  helgatheviking Feb 7 '12 at 15:28
add comment

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.

share|improve this answer
add comment

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

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.