Created
October 27, 2015 08:42
-
-
Save walterebert/05dceac3ecbf180de600 to your computer and use it in GitHub Desktop.
WordPress snippet: DNS prefetch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Prefetch DNS for given domains | |
* | |
* @param array $domains List of domain names | |
* | |
* More info: https://css-tricks.com/prefetching-preloading-prebrowsing/ | |
*/ | |
function my_dns_prefetch( $domains = array() ) { | |
if ( ! $domains ) { | |
// Default list | |
$domains = array( | |
'0.gravatar.com', | |
'1.gravatar.com', | |
'fonts.googleapis.com', // Google Fonts | |
'ajax.googleapis.com', // Google CDN | |
); | |
} | |
foreach ( $domains as $domain ) { | |
echo '<link rel="dns-prefetch" href="//' . esc_attr( $domain ) . "\" />\n"; | |
} | |
} | |
add_action( 'wp_head', 'my_dns_prefetch', 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment