WordPress Tips: How to remove the extra space between LI elements from wp_nav_menu

Here is the snippet of code I use to remove the extra space that WordPress adds to the end of

  • elements when you use wp_nav_menu to call in a menu:
    <?php $custommenu = wp_nav_menu ( array (
    		'container_class' => 'my-menu',
    		'theme_location' => 'primary',
                    'echo'            => 0
     ) );
    $custommenu = str_replace("\n", "", $custommenu);
    $custommenu = str_replace("\r", "", $custommenu);
    echo $custommenu;
    ?>