WordPress.org

Forums

Turn off TOP BAR (login bar/toolbar) for PUBLIC (not logged in) users (5 posts)

  1. webfixnow
    Member
    Posted 1 year ago #

    In your WP root directory locate wp-load.php and open it for editing using your favorite editor:

    Step 1 - Locate this line:

    wp();

    Step 2 - Add these lines just below the above line of code:

    if (!is_user_logged_in()) {
    	echo "<style type='text/css'>
    	#wpadminbar { display:none !important; }
    	html { margin-top: 0px !important; }
    	* html body { margin-top: 0px !important; }
    	</style>";
    }

    Note: The use of !important ensures that the property will always be applied no matter where that rule appears even if CSS further down the document injected from a template attempts to change the rules.

    Step 3 - Save the file.

    Users who are not logged in (PUBLIC) will not see the toolbar at the top of your pages. Since this modifies code in a core WP file you will need to add this each time you do an upgrade or refresh install of WP.

    Q: My users will be lost, where will my precious users login?
    A: Tell them to use the ADMIN url for the site if you have the login form enable and/or create a login menu link in your public menus.

  2. Andrew
    Nuh uh moderator
    Posted 1 year ago #

    When does the admin bar appear for non-logged in users (just wondering)?

  3. webfixnow
    Member
    Posted 1 year ago #

    Sorry, correction to title made. Login bar or WP dubbed "Toolbar."

  4. Andrew
    Nuh uh moderator
    Posted 1 year ago #

    Could you add this to your theme's functions.php file? Why does it need to be in the wp-load.php file?

    https://codex.wordpress.org/Child_Themes#Why_use_a_Child_Theme.3F

  5. webfixnow
    Member
    Posted 1 year ago #

    The purpose of adding it to the core files is to override any theme used so that when switching between themes one would not have to modify each themes code.

    After some extensive testing it seems that this location is not ideal because of the use of code in WP that uses header(); in some of the PHP files for redirection and in some cases causes a PHP error that headers cannot be modified because OUTPUT was already started.

    It is better to modify the header.php within each themes folder that you use to include the following code at the very top of the file:

    <?php
    if (!is_user_logged_in()) {
    	echo "<style type='text/css'>
    	#wpadminbar { display:none !important;}
    	html { margin-top: 0px !important; }
    	* html body { margin-top: 0px !important; }
    	</style>";
    }
    ?>

    I have tested the above with logging in and out, posting, etc, all without errors.

Topic Closed

This topic has been closed to new replies.

About this Topic