Add menu items to the admin bar for logged out uses

I want my main site ( for not logged in users) to show – login and register and forgot password links in the admin bar

  • Luís
    • Support

    Hi Muhammad Usman Ghani ,

    Hope you’re doing well today!

    To add the custom menu items to the admin bar to show a login, register and recover password, from what I tested in my install, you can use this snippet:

    add_action( 'admin_bar_menu', 'custom_toolbar_links', 999 );
    function custom_toolbar_links($wp_admin_bar){

    if ( !is_user_logged_in() ) {

    show_admin_bar( true );
    $wp_admin_bar->add_node(array(
    'id' => 'login',
    'title' => 'Log In',
    'href' => '/wp-login.php',
    ));

    $wp_admin_bar->add_node(array(
    'id' => 'register',
    'title' => 'Register',
    'href' => '/wp-login.php?action=register',
    ));

    $wp_admin_bar->add_node(array(
    'id' => 'password',
    'title' => 'Lost your password?',
    'href' => '/wp-login.php?action=lostpassword',
    ));
    }
    }

    You can use it in the theme functions.php, but to avoid lose this feature once you update the theme (in case you are not using a child theme), the best option is to use a mu-plugin.

    If you are interest, attached I sent the mu-plugin I used to test this, so:

    1) Download the .zip file attached and unzip it;

    2) Using FTP access, upload “admin_custom_links.php” to “wp-content/mu-plugins” folder.

    Note: If you don’t have a “mu-plugins” folder inside the “wp-content”, please create it.

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • Luís
    • Support

    Hi Muhammad Usman Ghani ,

    To do that you can use CSS:

    #wp-admin-bar-bp-register {
    display: none;
    }

    If you are not using a custom CSS plugin or your theme doesn’t have any section to add custom CSS, you can use the default option from WordPress: Appearance -> Customize -> Additional CSS.

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • Ash
    • WordPress Hacker

    Hello Muhammad Usman Ghani

    You can use the code provided by Luís directly:

    add_action( 'admin_bar_menu', 'custom_toolbar_links', 999 );
    function custom_toolbar_links($wp_admin_bar){

    if ( !is_user_logged_in() ) {

    show_admin_bar( true );
    $wp_admin_bar->add_node(array(
    'id' => 'login',
    'title' => 'Log In',
    'href' => '/wp-login.php',
    ));

    $wp_admin_bar->add_node(array(
    'id' => 'register',
    'title' => 'Register',
    'href' => '/wp-login.php?action=register',
    ));

    $wp_admin_bar->add_node(array(
    'id' => 'password',
    'title' => 'Lost your password?',
    'href' => '/wp-login.php?action=lostpassword',
    ));
    }
    }

    You can use this code in your child theme’s functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Customize admin dashboard area for all users.

    Would you please explain a bit of details about it? Do you want to rearrange the menus or change the design for dashhboard?

    If so, there are some admin plugins you can try like:

    https://colorlib.com/wp/wordpress-admin-dashboard-themes-plugins/

    https://wordpress.org/plugins/admin-menu-editor/

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,

    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.