sanitize_url() WordPress Function

The sanitize_url() function is a built-in Wordpress function that is used to clean up and sanitize a URL. This function is especially useful when dealing with user- inputted URLs, as it can help to prevent malicious code from being injected into a site. The sanitize_url() function can also be used to convert a URL into a standard format, which can make it easier to work with.

sanitize_url( string $url, string[] $protocols = null ) #

Performs esc_url() for database or redirect usage.


Description

This function is an alias for esc_url_raw().

Top ↑

See also


Top ↑

Parameters

$url

(string)(Required)The URL to be cleaned.

$protocols

(string[])(Optional) An array of acceptable protocols. Defaults to return value of wp_allowed_protocols().

Default value: null


Top ↑

Return

(string) The cleaned URL after esc_url() is run with the 'db' context.


Top ↑

Source

File: wp-includes/formatting.php

function sanitize_url( $url, $protocols = null ) {
	return esc_url_raw( $url, $protocols );
}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Restored (un-deprecated).
2.8.0Deprecated in favor of esc_url_raw().
2.3.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More