var_export( $hints );
给了我
array (
0 => \'https://s.w.org/images/core/emoji/2.4/svg/\',
)
这意味着数组键不是
s.w.org
但是
https://s.w.org/images/core/emoji/2.4/svg/
.
更改函数并将数组的键与完整url一起使用确实删除了s.w.org提示,同时仍然允许我使用资源提示。
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 );