Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

okay so I'm using the following code to get my links...

<?php wp_nav_menu( array('theme_location' => 'primary', 'container' => '', 'menu_class' => 'mainnav') ); ?>

This is my CSS for the nav...

.mainnav a {
    font-family: gooddog_plainregular, Arial, sans-serif;
    font-size: 30px;
    color: #ffea00;

.mainnav li:after {
content: url('images/nav-divider.png');

.mainnav li.last:after {
content: none;

.mainnav li {
    list-style: none;
    display: inline;
    font-size: 30px;
    margin-bottom: 10px;

.mainnav li.last {
    list-style: none;
    display: inline;
    font-size: 30px;
    margin-bottom: 10px;

The problem I'm having is that the li.last doesn't work, how do I add the class to it?

Thanks :)

share|improve this question
Are you trying to use the last-child pseudo-selector? –  s_ha_dum Apr 6 at 18:04
Thanks @s_ha_dum managed to get it done now! –  JoshuaBrand Apr 6 at 18:15
Do you plan to post the solution? –  s_ha_dum Apr 6 at 18:16
From the sounds of it, he wanted to add a class but ended up going with li:last-child as you suggested. –  Howdy_McGee Apr 9 at 18:15

1 Answer 1

Here's a function I use to add a first / last class to wp_nav_menu() items:

function add_first_and_last($items) {
    $items[1]->classes[] = 'first';
    $items[count($items)]->classes[] = 'last';
    return $items;
add_filter('wp_nav_menu_objects', 'add_first_and_last');
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.