0

I have an html containing &nbsp but I am unable to pass it through wp_kses(). I have tried adding allowed html array('&nbsp' => array(),) but does not seems to work. I there a way or I should not do that?

https://stackoverflow.com/questions/2300142/how-to-add-extra-whitespace-in-php/23844752

6
  • 1
    Did you use &nbsp or   ? And what's the exact wp_kses() code you used?
    – Sally CJ
    May 25, 2019 at 11:46
  • @SallyCJ not sure the difference but i used &nbsp for adding a white space ..then passed it through wp_kses()
    – user145078
    May 25, 2019 at 11:50
  • 1
      is the correct one - the ; is required. Otherwise, that's an invalid HTML entity and &nbsp would result in &nbsp.
    – Sally CJ
    May 25, 2019 at 11:52
  • 1
    @SallyCJ thank you! worked.
    – user145078
    May 25, 2019 at 11:56
  • 1
    You're welcome. And be sure to use valid HTML entities. :) (You can check some here)
    – Sally CJ
    May 25, 2019 at 12:02

1 Answer 1

3

not sure the difference but I used &nbsp for adding a white space ..then passed it through wp_kses()

The correct HTML entity for a non-breaking space is   — note the ; which is required and without it (i.e. &nbsp), the entity is not valid and when used with wp_kses(), you'd get &nbsp instead of a non-breaking space.

strangely it was working fine before I used wp_kses()

I'm pretty sure it's because the browser is smart enough and auto-corrected it to  . :-)

So, always use valid HTML entities and also tags (e.g. close a <div> with a </div>), regardless you use wp_kses() or not. Don't rely on "intelligent guess" or auto correction by the browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.