var_export( $hints );
gave me
array (
0 => 'https://s.w.org/images/core/emoji/2.4/svg/',
)
so that means the array key is not s.w.org
but https://s.w.org/images/core/emoji/2.4/svg/
.
Changing the function and using the key of the array with the full url did remove the s.w.org hint while still letting me use resource hints.
function resource_hints( $hints, $relation_type ) {
if ( 'dns-prefetch' === $relation_type ) {
// Export the value of the $hints variable
// to see what is inside of it.
var_export( $hints );
// Knowing that the url is not s.w.org but
// 'https://s.w.org/images/core/emoji/2.4/svg/'
// I can search for it in the array
$key = array_search( 'https://s.w.org/images/core/emoji/2.4/svg/', $hints, true );
if ( false !== $key ) {
// and here I can unset this key
unset( $hints[ $key ] );
}
// while I can add custom, site specific hints here
$hints[] = 'http://make.wordpress.org';
} elseif ( 'prerender' === $relation_type ) {
$hints[] = 'https://make.wordpress.org/great-again';
}
return $hints;
}
add_filter( 'wp_resource_hints', 'resource_hints', 999, 2 );