wp_internal_hosts
Allows you to extend the list of internal hosts (domains).
It affects wp_is_internal_link().
This hook can be useful when, for example, the domain has changed but some code still works with the old domain and the old domain must be added to the site's list of internal domains (hosts).
Usage
add_filter( 'wp_internal_hosts', 'wp_kama_internal_hosts_filter' );
/**
* Function for `wp_internal_hosts` filter-hook.
*
* @param string[] $internal_hosts An array of internal URL hostnames.
*
* @return string[]
*/
function wp_kama_internal_hosts_filter( $internal_hosts ){
// filter...
return $internal_hosts;
}
- $internal_hosts(array)
- An array of internal URL hostnames.
Examples
#1 Return a filtered array of internal hostnames
add_filter( 'wp_internal_hosts', 'air_internal_hosts_filter' );
/**
* Changes the list of internal hosts (domains).
*
* Callback for the 'wp_internal_hosts' filter.
*
* @param array $internal_hosts An array of internal URL hostnames.
*
* @return array
*/
function air_internal_hosts_filter( $internal_hosts ) {
$internal_hosts[] = 'dev.example.com';
$key = array_search( 'old.example.host', $internal_hosts );
if ( false !== $key ) {
unset( $internal_hosts[ $key ] );
}
return $internal_hosts;
}Changelog
| Since 6.2.0 | Introduced. |
Where the hook is called
wp_internal_hosts
wp-includes/link-template.php 4874-4879
$internal_hosts = apply_filters( 'wp_internal_hosts', array( wp_parse_url( home_url(), PHP_URL_HOST ), ) );