I'm not sure whether my question sounds promising or not but what I'm going to ask is very much relevant. So please read the full question before down voting or flag.
I'm trying to implement DNS Pre-fetching on my wordpress mu, as site by site approach. On my primary site I use a child theme, so I planned to put the following code in the function.php
to get what I'm looking for.
function dns_prefetch() {
echo '<link rel="dns-prefetch" href="//cdn.mysite.com" />';
echo '<link rel="dns-prefetch" href="//fonts.googleapis.com" />'
}
add_action('wp_head', 'dns_prefetch');
Now the way wordpress functions and hook works is it place this code into the <head>
section of the generated html where the wp_head()
has been called in the theme's (parent or child) header.php
But as per Google best coding practise, it is best to put DNS Prefetching code as top as possible. As per google it is better to use it like
<html>
<head>
<link rel="dns-prefetch" href="//cdn.mysite.com" />
<link rel="dns-prefetch" href="//fonts.googleapis.com" />
<!-- rest of my the code -->
</head>
But I have no idea how to do it, because all theme put there code first in the header.php
before calling wp-head
.
So, my question, is there any way to place those dns prefetching code just after starting <head>
tag? Please help.