Type something to search...
How to Add Google Fonts to WordPress?

How to Add Google Fonts to WordPress?

Google Fonts is the easiest way to get a WordPress site off the default system font stack and onto something that actually matches your brand, and it's free, with over a thousand font families available. The catch is that the fastest way to add a Google Font, pasting a <link> tag copied straight from the Google Fonts website, is also the way most likely to slow your site down and, in the EU, create a real GDPR problem, since it loads the font directly from Google's servers on every page view.

In this guide, you'll add Google Fonts to WordPress the proper way: enqueued correctly through WordPress's own asset system, with the right preconnect hints for performance, and with a fully self-hosted alternative if you want to remove the dependency on Google's servers entirely.

Why Not Just Paste the Embed Code From Google Fonts?

Google Fonts gives you a ready-to-use snippet like this:

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">

Pasting this directly into your theme's header.php works, but it comes with three real downsides:

  • It bypasses WordPress's dependency system. WordPress can't deduplicate, defer, or manage a font loaded this way the same way it manages properly enqueued styles, which matters the moment a plugin or another part of your theme also wants to load fonts.
  • It's a render-blocking request to a third-party domain. Every visitor's browser has to make a separate DNS lookup and connection to fonts.googleapis.com before it can even start downloading the font, adding real, measurable latency before your text renders.
  • It sends visitor IP addresses to Google. Loading any resource directly from Google's servers means Google's servers see the request, which is exactly the concern that led a German court to rule this a GDPR violation in 2022 without an explicit opt-in. If you have EU visitors, this is worth taking seriously, not just a theoretical risk.

The two methods below address the first two concerns. If the GDPR concern applies to your site, skip to the self-hosting section, which removes the Google dependency completely.

Method 1: Enqueue a Google Font Properly

Rather than a raw <link> tag, hook into wp_enqueue_scripts, the same way you'd load any other stylesheet:

add_action( 'wp_enqueue_scripts', function () {
    wp_enqueue_style(
        'google-font-poppins',
        'https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap',
        [],
        null
    );
} );

A couple of details worth understanding:

  • The fourth argument (null instead of a version number) tells WordPress not to append its own ?ver= query parameter to the URL. Google Fonts URLs already carry their own query string, and skipping the version parameter here keeps the URL exactly as Google expects it.
  • &display=swap in the URL is what makes text render immediately in a fallback font while the Google Font is still downloading, rather than leaving text invisible until the font arrives (the "flash of invisible text" problem). Always include this.

Add Preconnect Hints for Performance

The embed code from Google includes preconnect hints for a reason: they let the browser start the DNS lookup and TLS handshake to Google's font servers before it even discovers the <link> tag in your HTML. Add the same hints through WordPress's resource hints filter:

add_filter( 'wp_resource_hints', function ( $urls, $relation_type ) {
    if ( 'preconnect' === $relation_type ) {
        $urls[] = [
            'href'        => 'https://fonts.gstatic.com',
            'crossorigin' => 'anonymous',
        ];
        $urls[] = 'https://fonts.googleapis.com';
    }

    return $urls;
}, 10, 2 );

Apply the Font in Your CSS

Once enqueued, use the font family exactly as Google Fonts names it, with a sensible fallback:

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

h1, h2, h3 {
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
}

Method 2: Self-Host Google Fonts (No Google Request at All)

Self-hosting removes both the render-blocking third-party request and the GDPR question entirely, because the font files are served from your own domain, just like your theme's images. It takes a little more setup, but it's the more robust long-term choice.

Step 1: Download the Font Files

Google's own site doesn't offer direct .woff2 downloads for a specific weight, so use google-webfonts-helper, a well-known tool that repackages Google Fonts into ready-to-host files. Select your font, choose the weights you actually use (loading all nine weights of a font when you only use two wastes bandwidth for every visitor), and download the .woff2 files it generates.

Step 2: Add the Files to Your Theme

Upload the downloaded files to your theme, for example:

wp-content/themes/your-theme/fonts/poppins-v20-latin-400.woff2
wp-content/themes/your-theme/fonts/poppins-v20-latin-700.woff2

Step 3: Declare the Font With @font-face

Add this to your theme's main stylesheet:

@font-face {
    font-family: 'Poppins';
    src: url('fonts/poppins-v20-latin-400.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Poppins';
    src: url('fonts/poppins-v20-latin-700.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

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

Registering each weight as a separate @font-face block, all sharing the same font-family name, is what lets the browser automatically pick the right file whenever you use font-weight: 700 in your CSS, without you needing a different font-family value per weight.

Step 4: Preload the Font Actually Used Above the Fold

For the specific weight your header and body text use immediately on page load, add a preload hint so the browser fetches it at the highest priority, without waiting to parse your CSS file first:

add_action( 'wp_head', function () {
    $font_url = get_stylesheet_directory_uri() . '/fonts/poppins-v20-latin-400.woff2';
    echo '<link rel="preload" href="' . esc_url( $font_url ) . '" as="font" type="font/woff2" crossorigin>';
}, 1 );

The priority 1 on the hook keeps this preload tag as early in <head> as possible, which matters because preload hints only help if the browser sees them early.

Adding Google Fonts in a Block Theme (theme.json)

If your theme uses full site editing, the block editor gets its own font picker in the Styles panel, and it's driven by the fontFamilies setting in theme.json. This works alongside self-hosted files from Method 2:

{
    "version": 2,
    "settings": {
        "typography": {
            "fontFamilies": [
                {
                    "fontFamily": "'Poppins', sans-serif",
                    "slug": "poppins",
                    "name": "Poppins",
                    "fontFace": [
                        {
                            "fontFamily": "Poppins",
                            "fontWeight": "400",
                            "fontStyle": "normal",
                            "fontDisplay": "swap",
                            "src": [ "file:./assets/fonts/poppins-v20-latin-400.woff2" ]
                        },
                        {
                            "fontFamily": "Poppins",
                            "fontWeight": "700",
                            "fontStyle": "normal",
                            "fontDisplay": "swap",
                            "src": [ "file:./assets/fonts/poppins-v20-latin-700.woff2" ]
                        }
                    ]
                }
            ]
        }
    }
}

Once this is saved, "Poppins" appears as a selectable option in the block editor's typography controls for any block, with WordPress automatically generating the correct @font-face rules from the fontFace array, and editors never need to touch a font file directly.

Method 3: Use a Plugin

If you'd rather not manage font files manually, OMGF (Optimize My Google Fonts) automates everything in Method 2: it detects the Google Fonts your theme or plugins are already requesting, downloads them, and rewrites the enqueued URLs to serve from your own server instead, all through a settings screen. It's a solid choice if self-hosting appeals to you but manually downloading and preloading font files doesn't.

Frequently Asked Questions (FAQ) About Adding Google Fonts to WordPress

Not necessarily for the GDPR concern specifically, but self-hosting still has a real performance benefit for every site: it removes a third-party DNS lookup and connection, which is one of the more impactful things you can do for text rendering speed, independent of any privacy consideration.

This is almost always a font-display or loading-order issue rather than a browser-support issue, since woff2 (the format Google Fonts and google-webfonts-helper both provide) is supported by all modern browsers. Check your browser's Network tab to confirm the font file is actually loading with a 200 status, not a 404.

As few as your design uses, typically two to four (for example, 400 for body text and 600 or 700 for headings). Every additional weight is a separate file the browser has to download, and loading all nine weights a Google Font offers when you only style two is one of the most common self-inflicted performance issues.

Yes, there's no conflict in doing so, though it's simpler to standardize on one approach for maintainability. A common middle ground is self-hosting fonts used site-wide (body copy, headings) while leaving a rarely used decorative font on the CDN method if it's only used on a single page.

No, it generally helps. Without it, text using that font stays invisible until the font finishes downloading, which can worsen your Largest Contentful Paint score. font-display: swap shows readable text immediately in a fallback font, then swaps to the Google Font once it's ready.

Yes, self-hosted files are a snapshot from whenever you downloaded them, so you won't automatically receive Google's font updates the way the CDN method would. This is rarely an issue in practice, since Google Fonts updates are infrequent and mostly involve adding new language character sets, not changing how existing text renders.

Conclusion

Adding a Google Font to WordPress is simple, but doing it well means treating it like any other asset your site loads: enqueue it properly instead of pasting a raw <link> tag, add preconnect hints if you're using Google's CDN, and consider self-hosting if page speed or GDPR compliance matters for your audience. The self-hosting route takes an extra step or two, but it removes both the performance cost and the privacy question in one move, which is why it's worth the setup for most production sites.

Here are a few additional resources if you want to go deeper:

Tags :
Share :

Related Posts

Effortlessly Crafting Compelling WordPress Pages

Effortlessly Crafting Compelling WordPress Pages

As a website owner or content creator, having the ability to seamlessly add new pages to your WordPress site is crucial. Whether you're introducing a

Continue Reading
High Traffic Tips for WordPress Mastery 🚥

High Traffic Tips for WordPress Mastery 🚥

In our digital age, where online visibility is paramount, ensuring your WordPress site can handle surging traffic is crucial. Just like a finely-tune

Continue Reading
How Do I Change the WordPress Login URL?

How Do I Change the WordPress Login URL?

By default, every WordPress site's login page lives at the same predictable address: yoursite.com/wp-login.php (which also happens to redirect from

Continue Reading