Title: conditonal menu
Last modified: August 21, 2016

---

# conditonal menu

 *  [stiwdio](https://wordpress.org/support/users/stiwdio/)
 * (@stiwdio)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/conditonal-menu/)
 * 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)

 *  [CrouchingBruin](https://wordpress.org/support/users/crouchingbruin/)
 * (@crouchingbruin)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/conditonal-menu/#post-3955593)
 * 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](https://wordpress.org/support/users/stiwdio/)
 * (@stiwdio)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/conditonal-menu/#post-3955636)
 * Hi CrouchingBruin
 * Appreciate that – and in theory it makes sense but its not working
 * ANy suggestions?
 * Darren
 *  [CrouchingBruin](https://wordpress.org/support/users/crouchingbruin/)
 * (@crouchingbruin)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/conditonal-menu/#post-3955731)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [CrouchingBruin](https://wordpress.org/support/users/crouchingbruin/)
 * Last activity: [12 years, 6 months ago](https://wordpress.org/support/topic/conditonal-menu/#post-3955731)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
