phpwordpresswordpress-themingwp-nav-menu-item

Wordpress how to remove auto generated   in the navigation menu


I uploaded the pages including my header.php to wordpress and my header have auto generated &nbsp in it together with #text.

I tried adding this code but nothing happens.

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

Are there any solutions for this?

Edit:
This is where "&nbsp" shows up:
https://i.sstatic.net/yvQgI.jpg


Solution

  • So your theme is outputting &nbsp in the "nav menu items". So try to use the following code, see if it removes those extra spaces!

    add_filter( 'wp_nav_menu_objects', 'rempving_extra_spaces_from_nav_menu_items', 999);
    
    function rempving_extra_spaces_from_nav_menu_items($items)
    {
      $items = str_replace('            ',  '', $items);
      return $items;
    }
    

    Code goes into your functions.php file of your theme.