I just came over to this support page to request the same thing. There is more info on this here: https://wordpress.org/support/topic/remove-the-new-dns-prefetch-code
Do you think filtering out the s.w.org prefetching is a good fit for this plugin, Ryan?
Thanks!
Thread Starter
Ramanan
(@superpoincare)
Christee,
This is the way to do it:
https://core.trac.wordpress.org/ticket/37694
ie:
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 );
@ramanan – thanks, but that removes all prefetches, not just the emoji one. $hints, in my case, looks like this when it is passed in:
array(3) { [0]=> string(20) "fonts.googleapis.com" [1]=> string(16) "cdn.jsdelivr.net" [2]=> string(40) "https://s.w.org/images/core/emoji/2/svg/" }
Only key 2 should be removed.
Replacing the if in the function recommended above with this:
if ( 'dns-prefetch' === $relation_type ) {
$matches = preg_grep('/emoji/', $hints);
return array_diff( $hints, $matches );
}
does the trick. But my php is not strong, so this may not be the best or right way to do this.
Support for this has been added into the latest version.
Fantastic! Yes, the new version solves it.
Thanks for being so responsive!
I’m thinking the problem has risen again in WP 4.7
Can anyone confirm?
Thread Starter
Ramanan
(@superpoincare)
Thanks Ramanan, I updated the plugin to the new folder path as you pointed out and it did indeed correct the problem.
I’ll wait for Ryan to update the plugin through WP instead of manually changing them all.
Thanks again!
Thread Starter
Ramanan
(@superpoincare)
Thanks for confirming it work, semrocc.
A suggestion for Ryan for the update.
Since not everyone might update to 4.7, in the simplest solution, the plugin will need to keep track of the version. So folder /2/ for some versions and /2.2.1/ after that. But beyond a point, it will be difficult to keep track of this and become cumbersome.
So the solution will need to do something other than this.
Thread Starter
Ramanan
(@superpoincare)
Or else I can raise a ticket on core.trac to ask WordPress to modify their code, so that disabling it becomes simpler. Is that a good idea?
Yes Ramanan, raising a ticket would probably be a good thing. Dealing with path changes on a regular basis doesn’t make sense and would become cumbersome as you pointed out.
Sorry, I didn’t see this thread update until now. I’ll take a look at this and try to push out an update shortly.
Sorry for the long delay in fixing this. If any of you ever notice me miss a fix like this, please pester me via Twitter 🙂
I may have seen some emails about this, but just thought it was people using older versions of the plugin and so not paid it the attention I should have.
I’m uploading a new version just now, which fixes this problem. This is a crude solution though, and it will break if the URL is updated again. I’ll try to come up with an upgradeable solution so that this doesn’t keep happening regularly.
As of 4.7, the “hints” code above does not work. I’d like to remove all the dns-prefetch stuff that jetpack is adding.