WordPress adding google fonts the right way

Most of the time we need some different font than provided by theme developer or default html fonts, and adding them to WordPress the right way is important. These days lot of theme developers include options panel or some way or the other to let you select google fonts from a list of pre populated fonts to avoid the coding headache.
But still they don’t list all google fonts and you might need something different from the list they have.
Starting by making a child theme and creating a functions.php file add this code

function custom_google_fonts() {
wp_enqueue_style( 'custom-google-fonts', '//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,400,700,300', false );
add_action( 'wp_enqueue_scripts', 'custom_google_fonts' );

You can add multiple fonts like Open Sans, Lato etc
You will notice that i havnt used a protocol before //fonts this is to ensure that if your site is http or https their won’t be a conflict.

%d bloggers like this: