title: WordPress Toggle menu - keep the menu open on the current page
body: <p>I have a sidebar toggle menu in WordPress which is working fine, however when one of the toggle menu links is clicked and you are taken to the associated current page for that link, the toggle menu is closed. I am wanting it to stay open. </p>
  
  <p>I have found an example of a method that works but it is more for a static site and I was wondering how I could adapt it to my own existing jQuery code, as my menu is dynamically created within WordPress. The example code method that seems to work can be found here: <a href="http://jsfiddle.net/LcsLr/33/" rel="nofollow">jsfiddle.net/LcsLr/33/</a></p>
  
  <p>Any help would be most welcome!</p>
  
  <p>Below is my current html code:</p>
  
  <pre><code>&lt;div class="custom-sidebar"&gt;
  &lt;div class="nav-section-wrap"&gt;
  &lt;div class="menu-air-operators-menu-container"&gt;
  
  &lt;ul id="menu-custom" class="custom"&gt;
  &lt;li class="menu-item menu-item-type-post_type menu-item-object-page"&gt;&lt;a title="Top Level Link One" href="http://localhost/testsite/top-level-link-one/"&gt;TOP LEVEL LINK ONE&lt;/a&gt;&lt;/li&gt;
  
  &lt;li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-ancestor current-menu-parent"&gt;&lt;a title="Top Level Link Two" href="#"&gt;TOP LEVEL LINK TWO&lt;/a&gt;
  &lt;ul style="display: none;" class="sub-menu"&gt;
  &lt;li class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item current_page_item"&gt;&lt;a title="Subnav Link One" href="http://localhost/testsite/subnav-link-one/"&gt;Subnav Link One&lt;/a&gt;&lt;/li&gt;
  &lt;li class="menu-item menu-item-type-post_type menu-item-object-page"&gt;&lt;a title="Subnav Link Two" href="http://localhost/testsite/subnav-link-two/"&gt;Subnav Link Two&lt;/a&gt;&lt;/li&gt;
  &lt;li class="menu-item menu-item-type-post_type menu-item-object-page"&gt;&lt;a title="Subnav Link Three" href="http://localhost/testsite/subnav-link-three/"&gt;Subnav Link Three&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/li&gt;
  
  &lt;li class="menu-item menu-item-type-post_type menu-item-object-page"&gt;&lt;a title="Top Level Link Three" href="http://localhost/testsite/top-level-link-three/"&gt;TOP LEVEL LINK THREE&lt;/a&gt;&lt;/li&gt;
  &lt;li class="menu-item menu-item-type-post_type menu-item-object-page"&gt;&lt;a title="Top Level Link Four" href="http://localhost/testsite/top-level-link-four/"&gt;TOP LEVEL LINK FOUR&lt;/a&gt;&lt;/li&gt;
  &lt;li class="menu-item menu-item-type-post_type menu-item-object-page"&gt;&lt;a title="Top Level Link Five" href="http://localhost/testsite/top-level-link-five/"&gt;TOP LEVEL LINK FIVE&lt;/a&gt;&lt;/li&gt;
  &lt;li class="menu-item menu-item-type-post_type menu-item-object-page"&gt;&lt;a title="Top Level Link Six" href="http://localhost/testsite/top-level-link-six/"&gt;TOP LEVEL LINK SIX&lt;/a&gt;&lt;/li&gt;
  &lt;li class="menu-item menu-item-type-post_type menu-item-object-page"&gt;&lt;a title="Top Level Link Seven" href="http://localhost/testsite/top-level-link-seven/"&gt;TOP LEVEL LINK SEVEN&lt;/a&gt;&lt;/li&gt;
  &lt;li class="menu-item menu-item-type-post_type menu-item-object-page"&gt;&lt;a title="Top Level Link Eight" href="http://localhost/testsite/top-level-link-eight/"&gt;TOP LEVEL LINK EIGHT&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and my jQuery code:</p>
  
  <pre><code>(function($) { 
  
  // Sidebar Navigation
  $(document).ready(function() {
  
      // Hide the sub menu items first
      $("div.custom-sidebar div.custom-links-wrap ul &gt; li &gt; ul").hide();
  
      // On click
      $('div.custom-sidebar div.custom-links-wrap ul &gt; li &gt; a').click(function() {
          if($('ul', $(this).parent()).children().length) {
              $('ul', $(this).parent()).slideToggle("slow");
              return false;
          } else {
              return true;
          }
      });
  
      $('div.custom-sidebar div.custom-links-wrap ul &gt; li').click(function(e) {
          if ($(e.target).is("li")) {
              $('ul', this).slideToggle("slow");
              return false;
          } else {
              return true;
          }
  
      });
  
      });
  
  })(jQuery);
  </code></pre>
  
  <p>and my CSS:</p>
  
  <pre><code>div.custom-sidebar div.custom-links-wrap {background: url('images/links-bgr.png') repeat; padding: 14px 14px 14px 0px;}
  div.custom-sidebar div.custom-links-wrap ul li {font-weight: bold; background: none; padding-left: 18px; padding-top: 6px; padding-bottom: 6px;}
  div.custom-sidebar div.custom-links-wrap ul li.current-menu-item {background: url('images/links-current.png') no-repeat 0px 2px;}
  
  div.custom-sidebar div.custom-links-wrap ul li ul {margin-left: -18px;}
  div.custom-sidebar div.custom-links-wrap ul li ul li {font-weight: normal; padding-left: 36px;}
  div.custom-sidebar div.custom-links-wrap ul li ul li:last-child {padding-bottom: 0px;}
  div.custom-sidebar div.custom-links-wrap ul li ul li.current-menu-item {background: url('images/links-current.png') no-repeat 0px 2px;}
  </code></pre>