Can someone explain the use cases of esc_html?

esc_html() does two things:

  1. Checks for invalid UTF8 in a string.
  2. Converts a number of special characters into their HTML entities, specifically deals with: &, <, >, “, and ‘.

Using it instead of __(), _e and other i18n functions protects your website from possible errors that can occur with unaware translators who may use text that contains (1) invalid UTF8 characters or (2) unwanted HTML code. Trust me, many translators will be tempted to use some ‘nice’ HTML tags like <i>, <b> etc, even worse, they won’t close them correctly.

Leave a Comment

error code: 523