Created
July 8, 2022 19:36
-
-
Save BinaryMoon/1b282189892d945aa1f69ab8afdd6679 to your computer and use it in GitHub Desktop.
Change Google fonts for Bunny Fonts
This file contains hidden or 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: Bunny Hop. | |
* Plugin URI: https://prothemedesign.com | |
* Description: Swap Google fonts for Bunny Fonts to make the fonts GDPR compliant. | |
* Author: Ben Gillbanks | |
* Version: 1.0 | |
* Author URI: https://prothemedesign.com | |
*/ | |
/** | |
* Filter the incoming urls and replace google fonts ones with bunny fonts. | |
* | |
* @param string $src The string source to check. | |
* @return string | |
*/ | |
function bunny_fonts_swap_src( $src ){ | |
// Order is important here. | |
$src = str_replace( 'fonts.googleapis.com/css2', 'fonts.bunny.net/css', $src ); | |
$src = str_replace( 'fonts.googleapis.com/css', 'fonts.bunny.net/css', $src ); | |
$src = str_replace( 'fonts.googleapis.com', 'fonts.bunny.net', $src ); | |
return $src; | |
} | |
// Change font embed urls. | |
add_filter( 'style_loader_src', 'bunny_fonts_swap_src' ); | |
// Change dns-prefetch urls. | |
add_filter( 'wp_resource_hints', 'bunny_fonts_swap_src' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment