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

When using wp_nav_menu how do I make it so 'after' => does not show on the last element of the list?

share|improve this question

4 Answers 4

$('#menu-top-menu-1').children().last().each( function(){
    var endHtml = $(this).html().replace('<text you want to replace>','<text to replace it with>');         
share|improve this answer
Can't edit, but also need to change #menu-top-menu-1 to your menu ID – Jeff Mar 1 '11 at 20:44

While this can be done with JS, it might be more tidy to use wp_nav_menu filter, through which final output of menu is passed before returning/echoing.

share|improve this answer
You should expound on this – Carey Estes Feb 28 '13 at 4:00

You can hide it with CSS. For example, if your after looks like:

<?php wp_nav_menu(array('after' => '<span>|</span>')); ?>

Then your css:

.menu-item-num span { display: none; }
share|improve this answer

Found this on another Answer , but this question came up first when searching; so cross linking for future searchers

function replace_last_nav_item($items, $args) {
  return substr_replace($items, '', strrpos($items, $args->after), strlen($args->after));
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.