WordPress.org

Ready to get started?Download WordPress

Codex

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.

Contents

Description

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.

Usage

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

Parameters

$url
(string) (required) The URL to be cleaned.
Default: None
$protocols
(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
$context
(string) (optional) How the URL will be used. Default is 'display'.
Default: 'display'

Return Values

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

Examples

Notes

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

Changelog

Source File

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

Related

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