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 add this code in index.php. <div class="Div1"></div>. then write some css(absolution position) to the Div1. so when i login in my wordpress. the admin nav will push down some spaces to the site body. so the conetent shows unnormal. now, i want to add a class to <div class="Div1"> when logins. is there a way to get this.

share|improve this question

If you are using the body_class() function, a class admin-bar will be added automatically when the admin bar is active. For example:

<body class="home blog logged-in admin-bar">

You can then use that class in your CSS to specify specific rules:

.admin-bar .Div1 { /* custom styles */ }
share|improve this answer
+1 b/c you get a logged-in class right out of the box – helgatheviking Aug 2 '11 at 13:05

You can use jquery for this with a

<?php if ( is_user_logged_in() ) : ?>

And then use jquery to add class to div


So you would use this

    if ( is_user_logged_in() ) {
        echo '<script type="text/javascript">
        echo '';

Paste this in your functions.php file in the header.php or a plugin. Your choice. If the add class does not work try finding the div id that div1 class is inside of and use this instead 'jQuery("#divclassparent .Div1").addClass("logged-in");'

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.