Skip to content

Instantly share code, notes, and snippets.

@aisin
Last active August 29, 2015 14:03
Show Gist options
  • Save aisin/12598bd8586f98949324 to your computer and use it in GitHub Desktop.
Save aisin/12598bd8586f98949324 to your computer and use it in GitHub Desktop.
Replace Google Fonts&API with 360 in WordPress
<?php
// functions.php -- Theme
// 方法一:
if (!defined('ABSPATH')) exit;
class Replace_Google_Fonts
{
public function __construct()
{
add_filter('style_loader_tag', array($this, 'ohMyFont'), 888, 4);
}
public function ohMyFont($text)
{
return str_replace('//fonts.googleapis.com/', '//fonts.useso.com/', $text);
return str_replace('//themes.googleusercontent.com/', '//fonts.useso.com/', $text);
}
}
new Replace_Google_Fonts;
function devework_replace_open_sans() {
wp_deregister_style('open-sans');
wp_register_style( 'open-sans', 'http://fonts.useso.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600' );
wp_enqueue_style( 'open-sans');
}
add_action( 'wp_enqueue_scripts', 'devework_replace_open_sans' );
add_action('admin_enqueue_scripts', 'devework_replace_open_sans');
// 方法二:
function izt_cdn_callback($buffer) {return str_replace('googleapis.com', 'useso.com', $buffer);}
function izt_buffer_start() {ob_start("izt_cdn_callback");}
function izt_buffer_end() {ob_end_flush();}
add_action('init', 'izt_buffer_start');
add_action('shutdown', 'izt_buffer_end');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment