Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/clean url

This function has been deprecated. That means it has been replaced by a new function or is no longer supported, and may be removed from future versions. All code that uses this function should be converted to use its replacement if one exists. See also wp-includes/deprecated.php. Use any of these functions instead.

Use esc_url() instead. Usage is described here.


Checks and cleans a URL.

A number of characters are removed from the URL. If the URL is for displaying (the default behaviour) ampersands (&) are also replaced. The 'clean_url' filter is applied to the returned cleaned URL.


<?php clean_url$url$protocols$context ?>


(string) (required) The URL to be cleaned.
Default: None
(array) (optional) An array of acceptable protocols. Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' if not set.
Default: null
(string) (optional) How the URL will be used. Default is 'display'.
Default: 'display'

Return Values

The cleaned $url after the 'cleaned_url' filter is applied.



  • Uses: wp_kses_bad_protocol() to only permit protocols in the URL set via $protocols or the common ones set in the function.


Source File

clean_url() is located in wp-includes/formatting.php.


See also index of Function Reference and index of Template Tags.