WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

Sorry if my post duplicate but i can't find best solution for my problem. I'm newbie on develop WP theme. Now i'd like to add class to current li and last li, but i don't know how to do? Hope someone help.

Here is my HTML code:

        <li><a href="#" class="selected">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#" class="last">Contact</a></li>
share|improve this question

Wordpress does in fact add a current class by default:

check where it says:

<li id="menu-item-1688" class="current-menu-item">

Within your source code.

Now as for the other item, this is a bit tricky.

There is two ways to do it assuming that you need the last item for styling.

Option #1 is with pure CSS using the last-of-type selector.

Option #2, is using the get_wp_nav_menu as opposed to wp_nav_menu and once you are inside the foreach, you compare it using count and the current index of said foreach to add the css class dinamically.

Edit: If you are a bit new to Wordpress theming, I would definitely go with option number 1 despite not having full browser coverage.

share|improve this answer

Your Answer


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.