0

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.stack.imgur.com/yvQgI.jpg

Ruvee
  • 8,611
  • 4
  • 18
  • 44
Kirby Tan
  • 103
  • 11
  • 1
    In addition to removing the filter, there are other ways too, but you need to be more specific. There could be many sections and subsections in `header.php` file. Where do you see the "auto nbsp"? Is it a custom theme or you've created it? Please be more specific and give us more details so that we could try to debug it for you. Please take a moment and read [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Ruvee Sep 13 '21 at 07:57
  • @Ruvee This is where I saw the nbsp and this is a custom theme that I code from scratch. https://imgur.com/a/PT9GWDi – Kirby Tan Sep 13 '21 at 08:00
  • @Ruvee thank you so much! I am stuck with this for more than an hour and I have been applying some PHP functions too. – Kirby Tan Sep 13 '21 at 08:12

1 Answers1

1

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.

Ruvee
  • 8,611
  • 4
  • 18
  • 44
  • 1
    Ok that's fine, we'll make it work! So try to increase the priority of the filter hook from `10` to, let's say, `999`. See if it works. – Ruvee Sep 13 '21 at 08:36
  • Still not working, This is what my team mate says regarding this problem "I changed something inside a predetermined tag from the Wordpress admin panel, but it collapsed." (collapsed means nbsp are added in nav links) – Kirby Tan Sep 13 '21 at 08:40
  • Just updated my answer, please give it a shot! – Ruvee Sep 13 '21 at 09:17
  • 1
    While testing, is it now working. I'll accept this as the answer! Thank you so much :) – Kirby Tan Sep 13 '21 at 09:54