- Responsive Multi-Purpose Theme Framework! ›
- Forums ›
- Theme Support ›
- Account Menu in Top Menu Bar
your theme is great, the accounts in menu was successfully added, please how do i make stop appearing in other menu bars
Find this section of code:
add_filter( "wp_nav_menu_items", function ($items, $args){ $items .= firmasite_custom_bpmenu(); return $items; },10,2 );
and replace it with this:
add_filter( "wp_nav_menu_items", function ($items, $args){ if( $args->theme_location == 'main_menu' ) $items .= firmasite_custom_bpmenu(); return $items; },10,2 );
Now account menu will only show in main menu location.
I cant / shouldnt include this in theme. Its totally optional code and my primary mission about theme is keeping it clean as much as i can.
You can think this code as a perk
Oh, I see
I’ve found a weird behaviour using this code in my site. If the “anyone can register” option inside wordpress is unchecked, the account menu bar shows a button to REGISTER (although you can’t register when you click on it), but if I check the wp option to allow registrations then the REGISTER button doesn’t appear.
Yeah, i removed that option for myself, forgot to add check for allowing registration.
Here is new version:
global $blog_id; if ( 1 == $blog_id) : add_filter( "wp_nav_menu_items", function ($items, $args){ $items .= firmasite_custom_bpmenu(); return $items; },10,2 ); add_action("wp_head", function(){ ?> <style type="text/css" media="screen"> .dropdown-form { padding: 15px; } </style> <script type="text/javascript"> jQuery(document).ready(function($){ jQuery("li.member-menu ul.dropdown-menu span").addClass("label label-info"); }); </script> <?php },11); add_action("wp_footer","firmasite_custom_bpmenu"); function firmasite_custom_bpmenu() { ob_start(); ?> <?php if ( !is_user_logged_in() ) { ?> <li class="dropdown member-menu"><a class="dropdown-toggle" data-target="#" href="#"><i class="icon-briefcase"></i> <?php _e( 'Account', 'firmasite' ) ?> <b class="caret"></b></a> <ul class="dropdown-menu dropdown-form"> <li> <form name="login-form" id="login-form" action="<?php echo site_url( 'wp-login.php' ) ?>" method="post"> <div class="input-prepend"> <span class="add-on"><i class="icon-user"></i></span> <input type="text" name="log" id="user_login" value="" placeholder="<?php _e( 'Username', 'firmasite' ) ?>" /> </div> <div class="input-prepend"> <span class="add-on"><i class="icon-lock"></i></span> <input type="password" name="pwd" id="user_pass" value="" placeholder="<?php _e( 'Password', 'firmasite' ) ?>" /> </div> <label for="rememberme" class="checkbox"><input name="rememberme" type="checkbox" id="rememberme" value="forever" /> <?php esc_attr_e('Remember Me', 'firmasite'); ?></label> <input type="submit" name="wp-submit" id="wp-submit" value="<?php _e( 'Log In', 'firmasite' ) ?>"/> <?php if ( bp_get_signup_allowed() ) { ?> <input class="btn btn-primary pull-right" type="button" name="signup-submit" id="signup-submit" value="<?php _e( 'Create an Account', 'firmasite' ) ?>" onclick="location.href='<?php echo bp_signup_page() ?>'" /> <?php } ?> <?php // http://kovshenin.com/2012/current-url-in-wordpress/ global $wp; $current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) ); ?> <input type="hidden" name="redirect_to" value="<?php echo $current_url; ?>" /> <input type="hidden" name="testcookie" value="1" /> <?php do_action( 'bp_login_bar_logged_out' ) ?> </form> </li> <?php } else { ?> <li class="dropdown member-menu"><a class="dropdown-toggle" data-target="#" href="#"><i class="icon-user"></i> <?php echo bp_core_get_username( bp_loggedin_user_id() ); ?> <b class="caret"></b></a> <ul class="dropdown-menu"> <li> <?php firmasite_bp_adminbar_notifications_menu() ?> <?php bp_get_loggedin_user_nav() ?> <?php } ?> </ul> </li> <?php return ob_get_clean(); } function firmasite_bp_adminbar_notifications_menu() { if ( !is_user_logged_in() ) return false; echo '<li id="bp-adminbar-notifications-menu" class="dropdown-submenu"><a href="' . bp_loggedin_user_domain() . '">'; _e( 'Notifications', 'buddypress' ); if ( $notifications = bp_core_get_notifications_for_user( bp_loggedin_user_id() ) ) { ?> <span><?php echo count( $notifications ) ?></span> <?php } echo '</a>'; echo '<ul class="dropdown-menu">'; if ( $notifications ) { $counter = 0; for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) { $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?> <li<?php echo $alt ?>><?php echo $notifications[$i] ?></li> <?php $counter++; } } else { ?> <li><a href="<?php echo bp_loggedin_user_domain() ?>"><?php _e( 'No new notifications.', 'buddypress' ); ?></a></li> <?php } echo '</ul>'; echo '</li>'; } endif;
I updated code above. Try again. Probably new buddypress version have a different check system but it should be working now.
Hi Ünsal,
one question, I got the account showing nicely now in the top navigation. But how do I get it to show in the header as you have it on this site?
Thanks in advance!
Haime Croeze
To pull the button to the right side of the navigation, it needs to be put into an additional ul with a navbar-nav navbar-right class within the nav-main div.
<div id="nav-main" class="collapse navbar-collapse" role="navigation">
<ul class="menu-navigationsleiste" class="nav navbar-nav">
<!-- navigation -->
</ul>
<ul class="menu-navigationsleiste" class="nav navbar-nav navbar-right">
<!-- login-box-dropdown -->
</ul>
</div>
@Ünsal Your current solution displays the private message and notification counters only when I’m on the profile page (wordpress/members/username/). How can I display the counters on every page?
You must be logged in to reply to this topic.