How to enqueue Google Fonts using functions.php

July 1, 2021

1. Go to Google Fonts

2. Choose the font family you want to add

3. Copy the highlighted part

How to enqueue Google Fonts using functions.php

ex: https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap

4. Paste this in your theme’s functions.php

// Enqueue Google Fonts
function roboto_google_fonts() {
    wp_enqueue_style( 'roboto-google-fonts', 'https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap', false );
}
add_action( 'wp_enqueue_scripts', 'roboto_google_fonts' );

Replace these if you’re planning to use more Google Fonts in your website.

How to enqueue Google Fonts using functions.php

5. Use the CSS rule from Google Fonts in your CSS file

Get In Touch

Email: [email protected]


CAPTCHA image

This helps us prevent spam, thank you.



Categories