esc_html

Filters a string cleaned and escaped for output in HTML.

Description

apply_filters( 'esc_html', (string) $safe_text, (string) $text ); 

Text passed to esc_html() is stripped of invalid or special characters before output.

Parameters (2)

0. $safe_text (string)
The text after it has been escaped.
1. $text (string)
The text prior to being escaped.

Usage

To run the hook, copy the example below.
  1. $safe_text = apply_filters( 'esc_html', $safe_text, $text ); 
  2.  
  3. if ( !empty( $safe_text ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the esc_html callback 
  2. function filter_esc_html( $safe_text, $text ) { 
  3. // make filter magic happen here... 
  4. return $safe_text
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'esc_html', 'filter_esc_html', 10, 2 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'esc_html', 'filter_esc_html', 10, 2 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/formatting.php  
  1. return apply_filters( 'esc_html', $safe_text, $text );