Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#37694 closed defect (bug) (invalid)

Can't disable dns-prefetch to s.w.org

Reported by: superpoincare Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.6
Component: Script Loader Keywords:
Focuses: Cc:

Description (last modified by swissspidy)

According to the ticket #34292, dns-prefetch to s.w.org can be disabled with the following code (modified with the actual function):

function trac34292_example_resource_hints( $hints, $relation_type ) {
    if ( 'dns-prefetch' === $relation_type ) {
        return array_diff( $hints, wp_dependencies_unique_hosts() );

    return $hints;
add_filter( 'wp_resource_hints', 'trac34292_example_resource_hints', 10, 2 );

However this doesn't work. I still see the dns-prefetch in HTML.

Change History (3)

#1 @swissspidy
4 years ago

  • Component changed from General to Script Loader
  • Description modified (diff)
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hey there,

This code snippet I shared on #34292 was for removing resource hints for scripts and styles, not the s.w.org domain. That's why it doesn't work.

return array_diff( $hints, wp_dependencies_unique_hosts() ); means "keep all but scripts & styles".

Instead, you'd want array_diff( wp_dependencies_unique_hosts(), $hints ), i.e. "keep scripts & styles but nothing else.

#2 @creativeslice
4 years ago

To remove the s.w.org dns prefix you'll need to do this:

add_filter( 'emoji_svg_url', '__return_false' );

#3 @swissspidy
4 years ago

@creativeslice That will disable more stuff than just resource hints. I really recommend using the approach I mentioned above for this use case.

Note: See TracTickets for help on using tickets.