Created
June 14, 2022 17:04
-
-
Save nosilver4u/8de2d575f25c6a25ecf8b089acd179f6 to your computer and use it in GitHub Desktop.
SWIS Exclude Domain(s) from Prefetch/Preconnect
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 | |
/* | |
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