WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having trouble figuring out how to keep the current state active once on a single page of the post.

For example: Recipes displays a list of all my post that are under a specific category. Once you click one of the posts it brings you to single.php. The active state is only working when I am displaying all my post and is removed once I am on the single post.

How can I set up my code to display a current state to my link once on the single.php page?

I am not using wordpress menu system because I was unable to place my icons class inside of the link. A side note, I have my permalink setup to read category-name/post-name and the category name is recipe.

  <nav id="footerNav">
              <li><a href="<?php bloginfo('url'); ?>/about/" class="iconMain icon-about">About</a></li>
              <li><a href="<?php bloginfo('url'); ?>/recipes/" class="iconMain icon-recipes">Recipes</a></li>
              <li><a href="<?php bloginfo('url'); ?>/garden/" class="iconMain icon-garden">Garden</a></li>
              <li><a href="<?php bloginfo('url'); ?>/contribute/" class="iconMain icon-con">Contribute</a></li>

to display my current state i am using js

  $("#footerNav a").each(function() {   
        if (this.href == window.location.href) {
share|improve this question
I am not using wordpress menu system because I was unable to place my icons class inside of the link. why not ask how to do this instead? it's certainly possible. or using descendant css selectors, you wouldn't even need to add classes to anything, you could just use the existing classes on the li tags in combination with the body class. – Milo Jul 17 '14 at 18:49
I just figured out how to do that. I was not thinking correctly on how to make this work. Now I just need to figure out the active state for when I am on a single page again. @Milo – user3756781 Jul 17 '14 at 18:52
check out the examples on the body class page I linked above. there's one that shows you how to add categories to the body class, which you can target to highlight a specific menu item on a single post page. – Milo Jul 17 '14 at 19:11
wouldn't that trigger the body instead of the link? @milo – user3756781 Jul 17 '14 at 19:20
got it. Thank you for your help @Milo – user3756781 Jul 17 '14 at 19:40

Your Answer


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

Browse other questions tagged or ask your own question.