Skip to content

Instantly share code, notes, and snippets.

@BinaryMoon
Created July 8, 2022 19:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BinaryMoon/1b282189892d945aa1f69ab8afdd6679 to your computer and use it in GitHub Desktop.
Save BinaryMoon/1b282189892d945aa1f69ab8afdd6679 to your computer and use it in GitHub Desktop.
Change Google fonts for Bunny Fonts
<?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