• Hi,

    I would like to pre fetch some DNS with code snippet. I found n example piece of code that needs to be added to the functions.php.

    When I paste it into a snippet and save it doesn’t seem to be working. So my first question is whether the snippet is being included in the functions.php or do I need to add some additional info to the snippet? The second question is what priority should I set the snippet to please?

    e.g:

    //* Adding DNS Prefetching
    function wp_dns_prefetch() {
    echo ‘<meta http-equiv=”x-dns-prefetch-control” content=”on”>
    <link rel=”dns-prefetch” href=”//fonts.googleapis.com” />
    <link rel=”dns-prefetch” href=”//fonts.gstatic.com” />
    }
    add_action(‘wp_head’, ‘wp_dns_prefetch’, 0);

Viewing 1 replies (of 1 total)
  • @thegr8destructo,

    Above task is not recommended.

    Have you tried using WP Rocket? (it can do what you want plus a whole lot more, including speeding up your website). Note: We have no relationship with WP Rocket.

    Another option would be to add the following to the “Space before </head>” section of your website (easier, faster):

    < link rel="dns-prefetch" href="https://fonts.googleapis.com/" >
    < link rel="dns-prefetch" href="https://fonts.gstatic.com/" >

    If the above creates any issues or slows down your site, use:

    < link rel="preconnect" href="https://fonts.googleapis.com/" crossorigin >
    < link rel="dns-prefetch" href="https://fonts.googleapis.com/" >
    < link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin >
    < link rel="dns-prefetch" href="https://fonts.gstatic.com/" >

    Cheers!

Viewing 1 replies (of 1 total)

The topic ‘dns-prefetch’ is closed to new replies.