1

I'm trying to hide the "topbar" if user is logged in. Example: http://prntscr.com/chcwhl

My code at the moment is:

add_filter( 'wp_nav_menu_items', 'woohoo_add_auth_links', 10 , 2 );
function woohoo_add_auth_links( $items, $args )
{
    if( $args->theme_location == 'topmenu' )
    {
        if ( is_user_logged_in() ) {
            echo '<style>#topbar { display:none;}</style>';
        }
        elseif ( !is_user_logged_in() ) {
            $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
            $items .= '<li><a href="'. site_url('wp-login.php?action=register') .'">Register</a></li>';
        }
    }
    return $items;
}

I'm sure that the topbar is <div class="topbar"> so I'm a little confused why it's not hiding...

2
  • 1
    better (security, speed, reliability) to exclude it in php than to send it to the browser to then just hide it. Commented Sep 13, 2016 at 3:40
  • can you please provide a PHP example so i can get a better understanding of what you mean? Commented Sep 13, 2016 at 4:38

1 Answer 1

2

The # means ID. You can fix this by either using:

<div id="topbar">

Or:

echo '<style>.topbar { display:none;}</style>';

A # is css for ID, and a . is css for class.

Sign up to request clarification or add additional context in comments.

3 Comments

I've used # in my code and it won't work? I also tried with a . but that doesn't seem to work either
you cant dump css rules anywhere on the page. they need to be in the head
F12. Can you see console log error? at the browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.