How to Add Google Fonts to Your WordPress Site

Henrik L Jan 29, 2025 WordPress Typography
How do I change the text style on my website to make it look nicer with different font options?
What is the process for enqueueing Google Fonts in a WordPress theme to enhance typography?
Andy answered Jan 29, 2025

Why Use Google Fonts?

Google Fonts provides free, high-quality fonts that can dramatically improve your website's appearance and readability. They're optimized for web use and load quickly across different devices.

Method 1: Manual Implementation (Recommended for Developers)

Step 1: Select Your Font

  1. Visit Google Fonts
  2. Choose your desired font
  3. Copy the font URL from Google Fonts

Step 2: Enqueue the Font

Add this code to your theme's functions.php file to properly load the Google Font:

function add_google_fonts() {
    wp_enqueue_style('google-fonts', 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap', array(), null);
}
add_action('wp_enqueue_scripts', 'add_google_fonts');

Step 3: Apply the Font to Your CSS

Add this CSS to your theme's style.css file:

body {
    font-family: 'Open Sans', sans-serif;
}

Method 2: Using a Child Theme (Recommended for Theme Customization)

Create a child theme and add the font loading code to maintain changes through theme updates:

function child_theme_google_fonts() {
    wp_enqueue_style('child-google-fonts', 'https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap', array(), null);
}
add_action('wp_enqueue_scripts', 'child_theme_google_fonts', 20);

Best Practices & Security Considerations

  1. Performance

    • Load only the font weights you need
    • Use font-display: swap for better loading performance
    • Consider using preload for critical fonts
  2. Security

    • Always use HTTPS URLs for font loading
    • Verify font URLs are from fonts.googleapis.com
    • Keep your WordPress installation updated
  3. Common Pitfalls

    • Don't load too many font variations
    • Avoid mixing too many different fonts
    • Remember mobile performance

Plugin Solutions

  1. OMGF (Host Google Fonts Locally)

    • Hosts Google Fonts on your own server
    • Improves GDPR compliance
    • Download OMGF
  2. Elementor

    • Includes easy Google Fonts integration
    • Visual font selection interface
    • Get Elementor

Advanced Implementation

For more control over font loading, use this code to specify font-display and preload:

function advanced_google_fonts() {
    $font_url = 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap';
    
    // Add preload tag
    add_filter('style_loader_tag', function($html, $handle) {
        if ($handle === 'google-fonts') {
            return str_replace("rel='stylesheet'",
                "rel='preload' as='style' onload=\"this.rel='stylesheet'\"",
                $html);
        }
        return $html;
    }, 10, 2);
    
    wp_enqueue_style('google-fonts', $font_url, array(), null);
}
add_action('wp_enqueue_scripts', 'advanced_google_fonts');

Testing Your Implementation

  1. Check font loading in different browsers
  2. Verify mobile appearance
  3. Test website load speed (using tools like GTmetrix)
  4. Ensure fonts display correctly in various screen sizes

Remember to clear your cache after making font changes to see the updates.