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.

Is there a way to when logged in have the banner on my page move down so many specified pixels?

This is what it looks like when I'm logged in (as of course the dashboard bar at the top is there and pushes almost everything down (except my banner as it's absolutely positioned).

enter image description here

And of course this i what it looks like when I'm not logged in.

enter image description here

I looked on the wordpress codex and found this snippet of code

<?php
if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
} else {
    echo 'Welcome, visitor!';
}
?>

So I attempted to use it and tried to tell wordpress if the user is logged in show this banner with this styling, else show the other banner with that styling. However as I'm not a programmer this is all I got.

<?php
if ( is_user_logged_in() ) {
    <?php the_post_thumbnail();?>
            <?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('banner-widget')) : else : ?>  
            <p><img class="banner" src="<?php bloginfo('template_directory') ?>/img/BANNER1-averylawoffice.jpg" alt="Banner 1"></p>
            <?php endif; ?>
} else {
    <?php the_post_thumbnail();?>
            <?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('banner-widget')) : else : ?>  
            <p><img class="h3-banner" src="<?php bloginfo('template_directory') ?>/img/BANNER1-averylawoffice.jpg" alt="Banner 1"></p>
            <?php endif; ?>
}
?>

But it doesn't work. Of course.

So what can I do to have this banner move down when a user is logged in? Am I on the right track, just missing something?

share|improve this question
add comment

1 Answer

This is really just a CSS question. The admin bar does its best to do this for all sites by giving a top margin to the <html> element:

margin-top: 28px !important;

But if the theme uses certain positioning methods, that rule won't have the desired effect, which is what is happening in your case.

From what you've said, this might fix the issue:

body { position:relative; }

Also, WordPress adds an .admin-bar class to the <body> if you're using body_class(), so you could use that as a selector to fix the issue:

.admin-bar #my-logo { top: 28px; }

Either way, this is a CSS issue and not a PHP one. The actual CSS solution is off-topic for this site, so I'll leave you hear and you can figure it out.

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.