I am using WordPress for my site with the Ocean WP Theme and Elementor Page Builder. I can remove Google Fonts from the entire site using below PHP
snippet:
add_filter( 'style_loader_src', function($href){
if(strpos($href, "//fonts.googleapis/") === false) {
return $href;
}
return false;
});
But I don't want to remove Google Fonts from the entire site. Instead, I want to remove complete Google Fonts from a single page only, so that I can check and compare page speed with and without Google Fonts.
I am using WordPress for my site with the Ocean WP Theme and Elementor Page Builder. I can remove Google Fonts from the entire site using below PHP
snippet:
add_filter( 'style_loader_src', function($href){
if(strpos($href, "//fonts.googleapis/") === false) {
return $href;
}
return false;
});
But I don't want to remove Google Fonts from the entire site. Instead, I want to remove complete Google Fonts from a single page only, so that I can check and compare page speed with and without Google Fonts.
Share Improve this question edited Mar 26, 2020 at 14:49 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Mar 26, 2020 at 14:33 Brajmohan KumarBrajmohan Kumar 1251 silver badge6 bronze badges1 Answer
Reset to default 1This code filters all style url's. It returns the url if there is no reference to google fonts. It returns 'false' if there is a reference. What you want is to change the condition. It should only return false if there is a reference and you are on a certain page. Logically, this is equivalent to returning the url if there is no reference or you are not on that page. Like this:
if ((strpos($href, "//fonts.googleapis/") === false) || !is_page(12345)) {
Where you should replace 12345 with the ID or slug of the page you want to exclude.