WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Add login/user and notifications from admin bar to main nav (7 posts)

  1. myladeybugg
    Member
    Posted 1 year ago #

    I am looking to move or add part of the admin bar to my main nav bar. I would like to add the login/user and notifications to my main nav bar and hide the admin bar on the front end.

    I know how to remove it, but can't seem to figure out how to add these features to my nav bar.

    This is the portion of the admin bar I need:
    http://i.imgur.com/PmZMA.png

    And here is where I would like to add it:
    http://i.imgur.com/nBXh9.png

  2. bcworkz
    Member
    Posted 1 year ago #

    The technique required would be theme dependent. How is the main nav menu generated? Static html? PHP template? Menu Widget? Does it support pull downs like those used in the admin menu?

    The link to the profile page is simple enough, but the logout link's nonce must be added dynamically somehow, as it is different for every login.

  3. myladeybugg
    Member
    Posted 1 year ago #

    I am currently running a child theme of the BP Default theme. I coded the main nav into the header.php file.

    Here's a sample:

    <div id="primary_nav" class="clearfix">
    		<ul class="ipsList_inline" id="community_app_menu">
    
    			<li id="nav_app_ccs" class="left">
    			<a href="domain.com">Home</a>
    			</li>
    			<li id="nav_menu_1" class="left">
    			<a href="domain.com">Store</a>
    			</li>
    
                    </ul>
    </div>
  4. bcworkz
    Member
    Posted 1 year ago #

    OK, static html then. As it turns out, the nonce bit is easy as well - there's an app for that. err... rather a template tag for that. I neglected to mention though that you'd might want to conditionally display the menu items only to certain user roles, but the template tags are set up to display reasonable links to all users.

    It's up to you, but I'd rather have a link to the dashboard instead of directly to my profile page. And there's a tag for that too, so the conditional display becomes even less important, My example will only show the links to administrators, but you can use a different capability to cause display to more roles. You could even assign a custom capability if no capability common to all desired roles exists by default.

    My example only does a rudimentary side by side menu, if you need the pull down effect similar to the menu bar, it gets a bit more involved, there are many ways to implement it, working examples can be found on the internet. I'm not able to write code for it without doing some research myself.

    Insert above the closing </ul> tag for your menu.

    <?php
    if ( current_user_can( 'manage_options')) { //remove this line and final curly brace to display to all users, change manage_options to display to more but not all users
      wp_register( '<li id="nav_menu_6" class="left">'); //displays link to dashboard if logged in, or to registration page if anyone can register, otherwise does not display. Direct link to profile is 'domain.com/wp-admin/profile.php'
      echo '<li id="nav_menu_7" class="left">';
      wp_loginout();
      echo '</li>';
    } ?>
  5. myladeybugg
    Member
    Posted 1 year ago #

    Works great!

    Do you happen to know where I would find more template tags like the "wp_loginout()" tag?

  6. bcworkz
    Member
    Posted 1 year ago #

    There's always Template Tags :)

  7. myladeybugg
    Member
    Posted 1 year ago #

    :) Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic