SoFunction
Updated on 2025-03-10

PHP functions that escape HTML and filter links in WordPress use parsing

esc_html() (escape Html)
The esc_html() function is used to escape the Html code so that the Html code does not escape.

usage

esc_html( $text );

parameter

$text

(String) (must) string to escape.

Default value: None

Return value

(String) Returns the escaped character.

example

echo esc_html( '<a href="/">A link</a>' );

The above code will output:

WordPress function: esc_html() (escape Html)

(In order to prevent browser transcoding, I directly took a picture)

More

This function is located at: wp-includes/


esc_url() (Filter link)
Many URLs have minor errors. The esc_url() function can block or correct these errors, and can reject unsafe protocols.

The working content of the esc_url() function:

The default rejection is not the URL of the following protocol: defaulting to http, https, ftp, ftps, mailto, news, irc, gopher, nntp, feed and telnet
Remove invalid and dangerous characters
Convert characters to HTML entity characters
How to use

esc_url( $url, $protocols, $_context );

parameter

$url

(String) (must) URL to be filtered.

Default value: None

$protocols

(Array) (Optional) Can receive arrays of protocols. If not set, the default is: defaulting to http, https, ftp, ftps, mailto, news, irc, gopher, nntp, feed, and telnet.

Default value: None

$_context

(String) (optional) How to return URL.

Default value: (string) display

Return value

(String) Returns the filtered link.

example

&lt;?php echo esc_url( '' );//Output: ?>

More

This function is located at: wp-includes/