Quantcast
Channel: BIOSTALL » PHP
Viewing all articles
Browse latest Browse all 57

Remove Whitespace Between List Items Generated By wp_nav_menu()

$
0
0

Earlier today I was using wp_nav_menu() function within WordPress to output a navigation menu on a site. I was getting an issue however whereby the whitespace between the list items (<li>) was causing spaces between the menu items on the frontend. My list items had the ‘display’ CSS property set as ‘inline-block’ so I was getting visible gaps between them.

To conquer this I came up with the following snippet of code to strip out the whitespace:

echo preg_replace( '/li>\s+
  • FALSE, 'theme_location' => 'mainnav', 'echo'=>0 ) ) );

    Sticking with the normal use of wp_nav_menu(), instead of outputting it straight to the screen I set the ‘echo’ argument to FALSE (or zero) and run the output through preg_replace().


  • Viewing all articles
    Browse latest Browse all 57

    Latest Images

    Trending Articles



    Latest Images