esc_html_e

Home » Functions » esc_html_e

The WordPress function esc_html_e is used to display translated and sanitized HTML content on the screen. It ensures that any special characters in the text are properly encoded so they won’t break the layout or cause security issues. This function is commonly used when outputting user-generated content such as comments, forum posts, and contact form submissions.

The "esc" in the function name stands for "escape," meaning that any potentially harmful characters are escaped or replaced with safe alternatives. The "e" at the end of the function name stands for "echo," which means that the function will print the output directly to the screen instead of returning it as a value.

Here’s an example of how you can use esc_html_e function:

<?php
// Assume that $text variable contains user-generated content
$text = "Hello <script>alert('dangerous code');</script> World!";

// Output the sanitized and translated text
esc_html_e($text);
?>

In this example, any HTML tags and malicious script code in the user-generated content are properly encoded and replaced with safe alternatives before being output to the screen.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.