admin管理员组

文章数量:1426066

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?

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/questions/2300142/how-to-add-extra-whitespace-in-php/23844752

Share Improve this question edited May 25, 2019 at 11:52 asked May 25, 2019 at 11:06 user145078user145078 6
  • 1 Did you use &nbsp or   ? And what's the exact wp_kses() code you used? – Sally CJ Commented 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 Commented 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 Commented May 25, 2019 at 11:52
  • 1 @SallyCJ thank you! worked. – user145078 Commented 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 Commented May 25, 2019 at 12:02
 |  Show 1 more comment

1 Answer 1

Reset to default 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.

本文标签: escapingHow to allow ampnbsp with wpkses()