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.

My code call menu:

$defaults = array(
    'theme_location'  => '',
    'menu'            => '',
    'container'       => 'div',
    'container_class' => true,
    'container_id'    => 'btn',
    'menu_class'      => true,
    'menu_id'         => '',
    'echo'            => true,
    'fallback_cb'     => 'wp_page_menu',
    'before'          => '',
    'after'           => '<li class="btn_bar"><img width="18" height="38" src="http://localhost/client/fzsytech/wp-content/themes/fzsytech/img/pic-btn_bar.jpg"></li>',
    'link_before'     => '',
    'link_after'      => '',
    'items_wrap'      => '<ul>%3$s</ul>',
    'depth'           => 0,
    'walker'          => ''
);

wp_nav_menu( $defaults );

?>

And, my code when output :

<ul>
    <li id="menu-item-xx" class="blah blah">ABC</li>
    <li class="btn_bar"><img width="18" height="38" src="img/pic-btn_bar.jpg"></li>
    <li id="menu-item-xx" class="blah blah">DEF</li>
    <li class="btn_bar"><img width="18" height="38" src="img/pic-btn_bar.jpg"></li>

I want remove <li class="btn_bar"><img width="18" height="38" src="img/pic-btn_bar.jpg"></li> in the last menu ?

share|improve this question
2  
then do not use the line in array –  JMau Jul 6 '13 at 19:00
add comment

2 Answers

This will replace the last occurrence of your after string.

function replace_last_nav_item($items, $args) {
  return substr_replace($items, '', strrpos($items, $args->after), strlen($args->after));
}
add_filter('wp_nav_menu','replace_last_nav_item',100,2);

Pure CSS will do this too:

.btn_bar:last-child{display:none}
share|improve this answer
    
Thank you very much. I follow your way and it was just the way my –  Nessie Jul 6 '13 at 19:59
    
If this solved the problem please mark it as accepted. –  s_ha_dum Jul 6 '13 at 20:02
add comment
$after = '<li class="btn_bar"><img width="18" height="38" src="http://localhost/client/fzsytech/wp-content/themes/fzsytech/img/pic-btn_bar.jpg"></li>';
        $defaults = array(
                'theme_location'  => 'primary',
                'menu'            => '',
                'container'       => 'div',
                'container_class' => true,
                'container_id'    => 'btn',
                'menu_class'      => true,
                'menu_id'         => '',
                'echo'            => false,
                'fallback_cb'     => 'wp_page_menu',
                'before'          => '',
                'after'           => $after,
                'link_before'     => '',
                'link_after'      => '',
                'items_wrap'      => '<ul>%3$s</ul>',
                'depth'           => 0,
                'walker'          => ''
            );

            $menu = wp_nav_menu( $defaults );  
            echo substr($menu, 0, strripos($menu, $after)).'</ul>';
share|improve this answer
add comment

Your Answer

 
discard

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.