WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/esc html

Description

Escaping for HTML blocks.

Usage

<?php esc_html$text ?>

Parameters

$text
(string) (required) Text to escape
Default: None

Return Values

HTML (string) 
Escaped HTML string.

Examples

$html = esc_html( '<a href="http://www.example.com/">A link</a>' );

$html now contains this:

&lt;a href=&quot;http://www.example.com/&quot;&gt;A link&lt;/a&gt;

Which would be displayed in an HTML document as:

<a href="http://www.example.com/">A link</a>

Instead of this:

A link

Notes

  • Uses the 'esc_html' filter.
  • To safely display processed html, use either the 'wp_kses' or 'wp_kses_post' function.
  • This function will not double-escape special characters. For instance, echo esc_html( 'A &amp; B' ); will print A &amp; B, instead of A &amp;amp; B

Change Log

Source File

esc_html() is located in wp-includes/formatting.php.

Related

See: Data Validation article for an in-depth discussion of input and output sanitization.

See also index of Function Reference and index of Template Tags.