I've read the WP codex and several tutorials about data validation and sanitation in WordPress. Now I've got this simple example code:

$title = "<script>alert('Test')</script>"; echo esc_html($title);

According to the tutorials and the codex this should be the output: &lt;script&gt;alert&#40;&#39;test&#39;&#41;&lt;&#47;script&gt;

But on my website I get this: <script>alert('Test')</script>.

Am I doing something wrong? Because the XSS isn't being executed, so the esc_html filter is working correctly.

Thanks in advance!

| improve this question | | | | |

Your code is working correctly. If you look at the source code of the page, you will see:


When the above text gets processed for display by your browser, it then becomes


which is what you want to be displayed.

| improve this answer | | | | |
  • Thanks for your answer! You're correct, in the source it looks correct. Thanks! – Jason Lucas May 30 '13 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.