WordPress – เอา Google Fonts ออกไป!

wordpress-logo-680x400Web Font จาก Google มันสวยนะ แต่ว่า…มันก็โหลดช้าบ้าง เร็วบ้าง ถ้าจะให้เว็บของเราลื่นไหล ก็ควรจะโหลดใน Server ของเราเอง วิธีการกำจัดส่วนเกินออก ไม่ยากๆ มาดูกันเล๊ย


ให้เข้าไปจัดการที่ Theme ที่เราเลือก เช่นเราเลือก Theme portfolio-press เป้าหมายของเราก็จะอยู่ที่ wp-contentthemesportfolio-pressfunction.php

ก่อนอื่นให้เราค้นหาว่ามีการ โหลด Font เพิ่มเติมหรือไม่ หาคำว่า “font” ก่อนเลย ยกตัวอย่างว่า ผมเจอ

wp_enqueue_style( 'portfoliopress_fonts', '//fonts.googleapis.com/css?family=Open+Sans:400italic,400,600|Rokkitt:400,700', '', null, 'screen' );

ก็ทำการ Comment ไว้เป็น

// wp_enqueue_style( 'portfoliopress_fonts', '//fonts.googleapis.com/css?family=Open+Sans:400italic,400,600|Rokkitt:400,700', '', null, 'screen' );

จากนั้นให้ลงไปบรรทัดล่างสุดเลย แล้ว เติมคำสั่งดังนี้

/**
* Remove webfonts from Google
*/
function remove_open_sans() {
// Remove Open Sans font; causes issues with China
wp_deregister_style('open-sans');
wp_register_style('open-sans', false);
wp_enqueue_style('open-sans');
}
add_action( 'login_init', 'remove_open_sans' );            // Remove from the login page.
add_action( 'wp_enqueue_scripts', 'remove_open_sans' );    // Remove from the main site.
add_action( 'admin_enqueue_scripts', 'remove_open_sans' ); // Remove from the admin site.