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 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
add comment

2 Answers

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  
+1 b/c you get a logged-in class right out of the box –  helgatheviking Aug 2 '11 at 13:05
add comment

You can use jquery for this with a

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

And then use jquery to add class to div

jQuery(document).ready(function(){
jQuery(".Div1").addClass("logged-in");

So you would use this

<?php 
    if ( is_user_logged_in() ) {
        echo '<script type="text/javascript">
            jQuery(document).ready(function(){
            jQuery(".Div1").addClass("logged-in");
            '
    else
        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
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.