Skip to content

Instantly share code, notes, and snippets.

@nosilver4u
Created June 14, 2022 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nosilver4u/8de2d575f25c6a25ecf8b089acd179f6 to your computer and use it in GitHub Desktop.
Save nosilver4u/8de2d575f25c6a25ecf8b089acd179f6 to your computer and use it in GitHub Desktop.
SWIS Exclude Domain(s) from Prefetch/Preconnect
<?php
/*
Plugin Name: SWIS Pre-Hint Exclusions
Version: 1.0.0
*/
// This example uses the same function for both hooks.
add_filter( 'swis_skip_preconnect', 'my_swis_prehint_exclusions', 10, 2 );
add_filter( 'swis_skip_prefetch', 'my_swis_prehint_exclusions', 10, 2 );
function my_swis_prehint_exclusions( $skip, $domain ) {
if ( 'my.example.com' === $domain ) {
return true;
}
return $skip;
}
// Or you can use a separate function for preconnect and prefetch to exclude different domains for the two directives.
add_filter( 'swis_skip_preconnect', 'my_swis_preconnect_exclusions', 10, 2 );
function my_swis_preconnect_exclusions( $skip, $domain ) {
if ( 'no-preconnect.example.com' === $domain ) {
return true;
}
return $skip;
}
add_filter( 'swis_skip_preconnect', 'my_swis_prefetch_exclusions', 10, 2 );
function my_swis_prefetch_exclusions( $skip, $domain ) {
if ( 'no-prefetch.example.com' === $domain ) {
return true;
}
return $skip;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment