WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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've been asked to restyle the css of a WordPress website frontend. The website can't be in maintenance mode while working on it as it must stay up and running all the time. I assume that if I can add a small and unobtrusive condition in the header allowing the administrator to see a different css file than the users, I could edit the css and test the result while the users still see the original version of the website. This way I could work on the design without anyone noticing.

Can anyone tell me which WordPress function I should call on the header to switch the css file if and only if the user is an administrator?

The best would be not to edit the "functions.php" file or activate any plugin as I really don't want to mess with the website as it is (few chances but chances anyway). I would rather edit the "header.php" file in the theme folder in order to be sure nothing bad happens.

Thank you.

share|improve this question
Baylock, did my provided answer end up working for you? If so, click the check mark to the left of my answer. – Dwayne Charrington Feb 20 '13 at 23:18
up vote 1 down vote accepted

You should be able to simply check the capabilities of the currently logged in user. If they're an administrator the following example should do what you want it to. Just add this into your theme's functions.php file.

Please note this code is untested, but it should get you where you want to be. If the level_10 capability doesn't work you can check out the documentation for other user levels and capabilities here.

add_action( 'wp_enqueue_scripts', 'admin_only_stylesheet' );

function admin_only_stylesheet() {

    if ( current_user_can('level_10') {

        wp_register_style( 'admin-only-style', get_template_directory_uri() . '/css/admin-frontend-style.css', array(), '12345678', 'all' );

        wp_enqueue_style( 'admin-only-style' );


share|improve this answer
Thank you. Like I said, I would rather modify the header.php file and create a condition on the css link. Would the "if" statement above work there? I don't have access yet to the website to verify. – Baylock Feb 20 '13 at 0:20
Theoretically, yes the if statement should work just fine in this instance. I think I've used it outside of the context of a hook before and because it's a function that merely checks the current user global variable and checks against the info it has on that user, it should be fine. – Dwayne Charrington Feb 20 '13 at 5:11
Thank you DigitalSea. It worked like a charm. – Baylock Feb 21 '13 at 2:31
No worries Baylock, I'm glad I could help you out! – Dwayne Charrington Feb 21 '13 at 2:33
I would suggest to use current_user_can( 'manage_options' ) since the level system is outdated. – Hexodus Feb 12 '14 at 14:32

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.