• Not sure if its possible to do what I want, but basically I have a wordpress menu setup and the current menu item has a different color;

    But I have created a blog page which lists all the articles, but when the user clicks a single post the current active page is no longer highlighted

    Hope that makes sense, is there a way to add a function that if the current page is a single post then for instance, menu-item-1476 is given the class of current-menu-item so its highlighted?

    Sorry but hard to explain;

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can use jQuery/JavaScript to do what you want. If your theme supports the addition of custom scripts, copy and paste the code below. Or you can copy & paste the code into a Text widget in your sidebar (just leave the title of the widget blank and it won’t show up).

    <script>
    jQuery(document).ready(function($){
    
       if ($(".type-post").length == 1)
       {
          $("#menu-item-1476").addClass("current-menu-item");
       }
    });
    </script>

    So, if you understand jQuery, you’ll know that the ready function will execute once the page has loaded. The first line of the code checks to see if there is exactly one element with the class type-post on it. If so, it adds the class current-menu-item to the menu item that you have specified.

    Thread Starter stiwdio

    (@stiwdio)

    Hi CrouchingBruin

    Appreciate that – and in theory it makes sense but its not working

    ANy suggestions?

    Darren

    Can you provide a link to your site so I can see if the JavaScript is setting the class properly?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘conditonal menu’ is closed to new replies.