Use the WordPress function esc_url ()

Source: Internet
Author: User
Tags ftp gopher nntp

This WordPress function is usually used, especially when it is used to plug-ins or expand theme functions. I have written an article to note this and will use it later.

This esc_url function

Mainly used for URL filtering:

1. Deny URLs that are not the following protocols (defaulting to http, https, ftp, ftps, mailto, news, irc, gopher, nntp, feed, and telnet)
2. Remove invalid and dangerous characters.
3. Convert characters into HTML entities and convert & and single quotes (') into numeric entities: & #038, & #039.


$ Url
(String) (required) URL to be cleaned and filtered
Default: None

$ Protocols
(Array) (optional) can accept the protocol array. If not set, the default value is: 'http', 'http', 'ftp ', 'ftps', 'mailto ', 'news', 'irc', 'Gopher', 'nntp ', 'feed', and 'telnet '.
Default: None

$ _ Context
(String) (optional) how to return a URL.
Default: 'display'
The returned value is the filtered URL.

A simple example:

The code is as follows: Copy code

<? Php

Echo esc_url ('www ');
// The output content is:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.