Question

How to remove this from WP head:

<link rel='dns-prefetch' href='//maps.google.com'>

I had this also:

<link rel='dns-prefetch' href='//s.w.org'>

But, I removed it with this code inside my functions.php

add_filter( 'emoji_svg_url', '__return_false' ); 

Probably, this is added by one plugin exifografy, which can show map of location where image is taken. But, there is just few posts with map, so having this on all URL-s is just one more line of not used HTML code.

Était-ce utile?

La solution

Resource Hints is a smart feature added to WordPress version 4.6. I think it might improve your site speed. But if you want to disable it, try this:

remove_action('wp_head', 'wp_resource_hints', 2);

References

Autres conseils

/*
 *  Removes <link rel="prefetch" for WP assets not used in the theme
 * */
function remove_dns_prefetch($hints, $relation_type)
{
    if ('dns-prefetch' === $relation_type) {
        return array_diff(wp_dependencies_unique_hosts(), $hints);
    }
    return $hints;
}

add_filter('wp_resource_hints', 'remove_dns_prefetch', 10, 2);

I would suggest to remove it only if not used in the theme, this is the helper function I'm using

I did this by using wp_resource_hints filter and preg_match :

    /**
     * Removes dns-prefetchs links in header
     */
    public function remove_prefetchs($urls) {
        foreach ($urls as $key => $url) {
            if(preg_match('/google.com|code.jquery.com$/', $url) === 1) {
                unset( $urls[ $key ] );
            }
        }
        return $urls;
    }
add_filter( 'wp_resource_hints', array( $this, 'remove_prefetchs' ), 10, 2);
Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top