kses_allowed_protocols │ filter-hook │ WP 3.0.0

Allows you to add or remove protocols that may be used in URLs.

If a protocol is not allowed, the URL is removed when the content (HTML code) is sanitized. For example, if a viber://chat?number=+79281234567 link is added to the href attribute in a navigation menu, it will be removed.

Usage

add_filter( 'kses_allowed_protocols', 'wp_kama_kses_allowed_protocols_filter' );

/**
 * Function for `kses_allowed_protocols` filter-hook.
 * 
 * @param string[] $protocols Array of allowed protocols e.g. 'http', 'ftp', 'tel', and more.
 *
 * @return string[]
 */
function wp_kama_kses_allowed_protocols_filter( $protocols ){
	// filter...
	return $protocols;
}
$protocols(string[])

An array of allowed protocols, such as http, ftp, tel, and so on. See wp_allowed_protocols() for the complete list. For WordPress 5.8, it is:

$protocols = array(
	'http',
	'https',
	'ftp',
	'ftps',
	'mailto',
	'news',
	'irc',
	'irc6',
	'ircs',
	'gopher',
	'nntp',
	'feed',
	'telnet',
	'mms',
	'rtsp',
	'sms',
	'svn',
	'tel',
	'fax',
	'xmpp',
	'webcal',
	'urn'
);

Examples

#1 Add a Viber link to a menu (wp_nav_menu)

Changelog

Since 3.0.0 Introduced.

Where the hook is called

wp_allowed_protocols()
kses_allowed_protocols
wp-includes/functions.php 7346
$protocols = array_unique( (array) apply_filters( 'kses_allowed_protocols', $protocols ) );

Where the hook is used in WordPress

Usage not found.