WordPress Q&As Logo
WordPress Q&As Part of the Q&A Network
Q&A Logo

How can I enqueue Google Fonts correctly in WordPress?

Asked on Sep 29, 2025

Answer

To enqueue Google Fonts correctly in WordPress, you should use the `wp_enqueue_style` function within your theme's `functions.php` file. This ensures that the fonts are properly loaded and integrated with WordPress's built-in stylesheet management.
<!-- BEGIN COPY / PASTE -->
    function mytheme_enqueue_google_fonts() {
        wp_enqueue_style( 'mytheme-google-fonts', 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap', false );
    }
    add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_google_fonts' );
    <!-- END COPY / PASTE -->
Additional Comment:
  • Replace "Open+Sans:wght@400;700" with the desired font family and weights.
  • Ensure that the function name `mytheme_enqueue_google_fonts` is unique to avoid conflicts.
  • Use `wp_enqueue_scripts` action to ensure styles are loaded properly in the front-end.
  • Consider using the `display=swap` parameter for better font loading performance.
✅ Answered with WordPress best practices.

← Back to All Questions
The Q&A Network