admin管理员组文章数量:1392896
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.
本文标签: filtersHow to remove google font in WordPress for only single page
版权声明:本文标题:filters - How to remove google font in WordPress for only single page? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744633811a2616699.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论