W3cubDocs

/WordPress

wp_is_internal_link( string $link ): bool

Determines whether or not the specified URL is of a host included in the internal hosts list.

Description

See also

Parameters

$linkstringrequired
The URL to test.

Return

bool Returns true for internal URLs and false for all other URLs.

Source

function wp_is_internal_link( $link ) {
	$link = strtolower( $link );
	if ( in_array( wp_parse_url( $link, PHP_URL_SCHEME ), wp_allowed_protocols(), true ) ) {
		return in_array( wp_parse_url( $link, PHP_URL_HOST ), wp_internal_hosts(), true );
	}
	return false;
}

Changelog

Version Description
6.2.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_is_internal_link