Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a Menu (for the nav bar) it is placed in a copy of the header.php file in my child theme right below:

 <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary','container' => '' ) ); ?>

It works fine EXCEPT the CSS for the Active Selected menu item is not working for everything but "Home".

This changes the background for "Home" when selected but none of the other top menu items.

#access ul li.current_page_item > a, #access ul li.current-menu-ancestor > a, #access    ul li.current-menu-item > a, #access li.selected > a, #access ul li.current-menu-parent > a, #access ul li.current_page_item, #access ul li.current-menu-item, #access li.selected {
background-color: #1E0D51 !important;
}

All the CSS does show up for Hover.

I have spent hours on this and can not figure out what the problem is.

Any insights or ideas are gratefully appreciated.

Thanks Tim

Place in header.php after <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary','container' => '' ) ); ?>

<ul> 
            <?php if ( is_user_logged_in() ) { ?> 
            <li class="menu-item"id="menu-item-22"> <a href="<?php echo                                               bp_loggedin_user_domain() ?>activity/just-me/">My Wall</a>
          <ul class="sub-menu"> 

            <li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?       >activity/friends/">My Friends' Activities</a></li>
            <li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?    >profile/edit/group/1">Edit My Profile</a></li>
   </ul> 
 </li>
 <!-- new menu here  edit the links-->
 <li class="menu-item"id="menu-item-22"> <a href="http://maolalumnet.org/members/">All Members</a>
        <ul class="sub-menu"> 

            <li class="menu-item"> </li>
   </ul> 
 </li>
 <!--end menu--->
 <!-- new menu here  edit the links-->
 <li class="menu-item"id="menu-item-22"> <a href="http://maolalumnet.org/groups/">All Groups</a>
        <ul class="sub-menu"> 

            <li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>groups/">My Groups</a></li>
   </ul> 
</li>
<!--end menu--->
<!-- new menu here  edit the links-->
<li class="menu-item"id="menu-item-22"> <a href="http://maolalumnet.org/events/">All Events</a>
        <ul class="sub-menu"> 

            <li class="menu-item"> <a href="http://maolalumnet.org/events-calander/">Calendar View</a></li>
            <li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>events/my-events/">My Events</a></li>
            <li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>events/my-events/">Create an Event</a></li>
   </ul> 
</li>
<!--end menu--->
<?php ;} ?>
share|improve this question
    
Seeing your CSS would be more beneficial. Have you tried the built-in CSS selector .current-menu-item? WordPress places this class on whatever menu item is current being viewed. If the current view is a child or grandchild of the menu item, additional CSS selectors are attached. I would highly recommend using a tool like Firebug to check it out. –  cmegown Mar 12 '12 at 16:55
add comment

1 Answer

up vote 1 down vote accepted

I forgot to add this is for BUDDYPRESS

This worked:

Add to functions.php:

//--Current Page URL
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .=   $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

Add to header.php before </header>

<?php

                if ( curPageURL() == bp_loggedin_user_domain().'activity/just-me/') {   $current = 'one'; }
                 elseif ( curPageURL() == bp_loggedin_user_domain().'activity/friends/') { $current = 'one'; }
                 elseif ( curPageURL() == bp_loggedin_user_domain().'profile/edit/group/1') { $current = 'one'; }

                 elseif ( curPageURL() == 'http://my_site.com/members/') { $current = 'two'; }

                 elseif ( curPageURL() == 'http://my_site.com/groups/'){ $current = 'three'; }
                 elseif ( curPageURL() == bp_loggedin_user_domain().'groups/') { $current = 'three'; }

                 elseif ( curPageURL() == 'http://my_site.com/events/') { $current = 'four'; }
                 elseif ( curPageURL() == bp_loggedin_user_domain().'events/my-events/') { $current =  'four';}                    

?>

            <style type="text/css">
              #<?php echo $current; ?> {
             background-color: #1E0D51;
             font-family: Comic Sans MS,Comic Sans MS5,cursive;
             }                 } 
            </style>

And the original code has been slightly altered to this:

<ul> 

            <li class="menu-item"id="one"> <a href="<?php echo bp_loggedin_user_domain() ?>activity/just-me/">My Wall</a>
        <ul class="sub-menu"> 

            <li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>activity/friends/">My Friends' Activities</a></li>
            <li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>profile/edit/group/1">Edit My Profile</a></li>
     </ul> 
 </li>
<!-- new menu here  edit the links-->
<li class="menu-item"id="two"> <a href="http://my_site.com/members/">All Members</a>
        <ul class="sub-menu"> 

            <li class="menu-item"> </li>
   </ul> 
 </li>
<!--end menu--->
<!-- new menu here  edit the links-->
<li class="menu-item"id="three"> <a href="http://my_site.com/groups/">All Groups</a>
        <ul class="sub-menu"> 

            <li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>groups/">My Groups</a></li>
   </ul> 
 </li>
<!--end menu--->
<!-- new menu here  edit the links-->
<li class="menu-item"id="four"> <a href="http://my_site.com/events/">All Events</a>
        <ul class="sub-menu"> 

            <li class="menu-item"> <a href="http://my_site.com/events-calander/">Calendar View</a></li>
            <li class="menu-item"id="four"> <a href="<?php echo bp_loggedin_user_domain() ?>events/my-events/">My Events</a></li>
            <li class="menu-item"id="four"> <a href="<?php echo bp_loggedin_user_domain() ?>events/my-events/">Create an Event</a></li>
   </ul> 
 </li>
<!--end menu--->
<?php 
} 
}
add_action("bp_nav_items","add_profile_link_to_nav");
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.