最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filters - How to remove google font in WordPress for only single page?

programmeradmin5浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

This 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.

发布评论

评论列表(0)

  1. 暂无评论