admin管理员组

文章数量:1300110

How to remove this from WP head:

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

I had this also:

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

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.

How to remove this from WP head:

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

I had this also:

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

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.

Share Improve this question asked Aug 22, 2016 at 16:22 Advanced SEOAdvanced SEO 6892 gold badges16 silver badges41 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 6

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

  • wp_head resource hints
  • wp_resource_hints filter
/*
 *  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|code.jquery$/', $url) === 1) {
                unset( $urls[ $key ] );
            }
        }
        return $urls;
    }
add_filter( 'wp_resource_hints', array( $this, 'remove_prefetchs' ), 10, 2);

本文标签: Remove rel39dnsprefetch39 href39mapsgooglecom39 from wphead