I have created a child theme of twenty fifteen. I’d like to remove the google fonts loaded in wp_head but I can’t get it to work. What is loaded is:
<link rel='stylesheet' id='twentyfifteen-fonts-css' href='//fonts.googleapis.com/css?family=Noto+Sans%3A400italic%2C700italic%2C400%2C700%7CNoto+Serif%3A400italic%2C700italic%2C400%2C700%7CInconsolata%3A400%2C700&subset=latin%2Clatin-ext' type='text/css' media='all' />
I’ve created a function.php in my child theme but I can’t figure out how to remove this. I’ve gotten other things remove using:
remove_action('wp_head', '...');
But I can’t figure out how to remove the fonts.
Also, any tips on how to remove the IE condition statements and css would be very helpful!
Thanks!
TwentyFifteen uses a custom function to build a Google fonts URL which is then used with
wp_enqueue_style()
. To remove Google fonts create a function in your child theme to dequeue the stylesheet.Use the
wp_enqueue_scripts
hook and make sure to give it a higher priority than the hook in the parent theme. The default is 10 so in my example I use 20.Example:
Deregister/Dequeue styles is best practice
https://codex.wordpress.org/Function_Reference/wp_deregister_style
https://codex.wordpress.org/Function_Reference/wp_dequeue_style
But you can use
'style_loader_src'
filter too, to filter out styles with string condition, or other conditions, here is example for google fontsOpen theme’s
functions.php
and find a function calledtwentyfifteen_fonts_url()
– it handles all the fonts stuff. In default file it starts on line 144. Edit it to your needs.Other options:
wp_deregister_style()
function to manually unregister that stylesheet. See here.As for the IE conditional – check the next function in
functions.php
, calledtwentyfifteen_scripts()
. It starts on line 196.