Home » Functions » esc_html

Function Name: esc_html

If you’re working with WordPress, you may come across user-generated content that contains HTML tags. While this can be useful for formatting, it can also be a security risk. Escaping HTML is a way of protecting your website from potential security threats. In WordPress, the esc_html function is used to escape any HTML tags, replacing them with their HTML entities.

Essentially, the esc_html function is used to sanitize user input when displaying it on your website. This ensures that any HTML tags are properly encoded, preventing them from being interpreted as actual HTML code.

Here’s an example usage code:

$post_title = get_the_title();
echo esc_html( $post_title );

In this example, we’re retrieving the title of a post using the get_the_title function. We then pass this value to the esc_html function, which encodes any HTML tags in the title before outputting it to the screen.

Overall, the esc_html function is an important tool for maintaining the security of your WordPress website.

Learn More on

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