Turn off WordPress automatically loaded open sans font, always connect googleapi.com, cause open WordPress very slow

Source: Internet
Author: User
Tags sublime editor wordpress blog goagent

Transfer from http://www.xuanfengge.com/turn-off-automatic-loading-wordpress-open-sans-fonts.html

Search on the Internet, there are four ways.

(1) Install the plug-in that others have developed for this issue to load Google Fonts

(2) Modify the filter function function.php

(3) Manually replace the path to the loading Google fonts yourself

(4) Using goagent

I used the first method to solve the problem,

Download plugin:

1. Plug-in one

name : Remove Open Sans font Link from WP core

Address : http://wordpress.org/plugins/remove-open-sans-font-from-wp-core/

Introduction : Remove the WP core Google font link. installs ' Remove Open Sans font Link from WP core ' plugin on your WordPress blog, so it'll doesn ' t load Open Sans fo NT from Google fonts.

2. Plug-in two

name : Disable Google Fonts

Address : http://wordpress.org/plugins/disable-google-fonts/

Introduction : Another similar plugin

Put both of these plugins down.

Second, functions.php filtration Introduction

Add one of the code to the end of the functions.php file in the topic. This method works only in the foreground and is not valid in the background interface because only the subject code is modified.

1. Code One//Remove Open Sans that WP adds from Frontendif (! Function_exists(' Remove_wp_open_sans ')) : function remove_wp_open_sans() { wp_deregister_style( ' Open-sans ' ); wp_register_style( ' Open-sans ', false );     } add_action(' wp_enqueue_scripts ', ' Remove_wp_open_sans '); //uncomment below to remove from admin //add_action (' admin_enqueue_scripts ', ' Remove_wp_open_sans '); endif;

function Remove_open_sans () {wp_deregister_style (' Open-sans '); Wp_register_style (' Open-sans ', false); Wp_enqueue_style (' Open-sans ', '); } add_action (' init ', ' remove_open_s

2, code two

function remove_open_sans() { wp_deregister_style( ' Open-sans ' ); wp_register_style( ' Open-sans ', false ); wp_enqueue_style(' Open-sans ','); }    add_action( ' init ', ' Remove_open_sans ' );

Three, one key replacement program code

Brief introduction

This script can not only solve WordPress due to Google CDN Resources caused by the slow loading of the site, and as long as the support of PHP space can also solve any build program because of Google CDN resources caused by slow loading problems.

How to use

1. Upload the downloaded php script (PS: script to the Google fonts introduced by the program and other Google CDN Resources to replace the 360 resources) to the site root directory . 2. After successfully uploading the file, directly use the browser to access the file, and click Start to perform the operation. 3. Program execution, this time can go to experience the smooth effect (one key to solve the front desk, the background Google font problems)

Script download

NET-disk version: Http://pan.baidu.com/s/1sjtwPYl

Run

Top notice alerts can be ignored

Summary

If the host of the win system may access the script, there will be a warning error, either directly or slightly. The part of the red box is the list of file names of the files scanned by the script, and yes and no indicates whether the file queries the specified characters. (PS: This script can also be used to scan black chains and malicious code.) ) (Thanks to the script provided by v7v3.com)

Iv. Use of Goagent

If you are using the Goagent System Agent, you can add a toggle rule in the Switchysharp or Autoproxy option:

rule name : google-fonts

URL mode : *://*.googleusercontent.com/*

Situational Mode : goagent

Font

Open sans fonts look good, if you use a foreign theme and use this font, or want to keep, you can install the font locally. Copy the files inside the archive to the C-Drive Fonts folder to complete the installation.

: Http://xuanfengge.com/demo/201406/Open-Sans.zip

Effect Preview : Http://www.google.com/fonts/specimen/Open+Sans

Analysis Reason

Because of the recent Google is strong, it is difficult to open, causing the site in the reference to Google resources, such as fonts, jquery and other files, there will be a serious time-out situation, resulting in a very slow site opening. This may be one of the reasons, but what exactly, and how to find the root cause? Below is a simple analysis (under the Chrome browser)

1. View Network Connections

When the site is not fully open, the lower-left corner of chrome displays the status of the network request, such as "Resolving Host", "Waiting for tieba.baidu.com response". If you find that the wait time for a response is too long (typically an outbound resource, such as an avatar, font), then this is the reason for slowing down the speed.

2. View Network Requests

F12 or right-click "Review Element" to enter the developer mode, select "Network", F5 refresh the page and view the online request of the war situation. After waiting for a full load, view all requests, the red part is an access error, the resource is not requested, and the time of the item can be seen when the request is taken to the result. If the time is too long, it is also a reason to slow down the site access speed

3. Locating the source

Based on the above description, find the request with slow access, click to view the details. If there is a Google font loading problem, such as the request URL is http://fonts.googleapis.com/css?family=Open+Sans&ver=3.9.1. The developer panel switches to the elements page, ctrl+f searches for "Google" or other keywords, where you can locate the request in your code.

4. Document positioning

The reason is found above, but perhaps the code is not in header.php or index.php. Then you need to search using the editor and search in the topic. If you use the sublime editor, drag the theme folder to the editor, and in the project right click "Find in Folder", enter the keyword, you can locate the code location in multiple files. When the code is found, comment the relevant code. Such as:

If you find and comment on the code (functions.php), you can resolve the problem that the http://fonts.googleapis.com/css?family=Open+Sans&ver=3.9.1 request occurred

Wp_enqueue_style (' Google-font ', ' http://fonts.googleapis.com/css?family= '. $all _font);

Note the following code (html5lightbox.js) resolves an issue that occurs with Http://fonts.googleapis.com/css?family=Armata requests

//var fontref = ("https:" = = Document.location.protocol?) HTTPS ":" http ") +"://fonts.googleapis.com/css?family=armata ";//var fontlink = document.createelement ("link");//Fontlink.setattribute ("rel", "stylesheet");//Fontlink.setattribute ("type", "Text/css");//Fontlink.setattribute ("href", fontref);//document.getElementsByTagName ("Head") [0].appendchild (Fontlink);

If you don't feel fast enough, do more optimizations like CDN acceleration, caching, servers, etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.