DEV Community

Pranto Mollick
Pranto Mollick

Posted on

🎓 Mastering WordPress Font Enqueue with Google Fonts: Real Interview Questions with Bilingual Explanations

If you're a WordPress developer aiming to crack interviews or just want to level up your theme development game, understanding how to enqueue Google Fonts is crucial. In this post, we’ll dive into a real-world code snippet and break down everything from function logic to interview questions — all explained in English and Bengali with memory tricks and analogies.


💡 The Code We’ll Explore

function gamestore_google_fonts() {
    $font_url = ''; 
    $font_family = 'Urbanist:ital,wght@0,400;0,700;1,400;1,700';

    if ('off' !== _x( 'on', 'Google font: on or off', 'gamestore' )) {
        $query_args = array(
            'family' => $font_family,
            'subset' => 'latin,latin-ext',
            'display' => 'swap',
        );
        $font_url = add_query_arg( $query_args, '//fonts.googleapis.com/css2' );
    }

    return $font_url;
}

function gamestore_google_font_script() {
    $font_url = gamestore_google_fonts();
    if ( ! empty( $font_url ) ) {
        wp_enqueue_style( 'gamestore-google-fonts', esc_url( $font_url ), array(), wp_get_theme()->get( 'Version' ) );
    }
}
add_action( 'wp_enqueue_scripts', 'gamestore_google_font_script' );
Enter fullscreen mode Exit fullscreen mode

đŸŽ¯ What This Code Does

✅ Dynamically builds a Google Fonts URL
✅ Loads the font into your theme using wp_enqueue_style()
✅ Supports conditional disabling and version-controlled caching


🧠 Real Interview Questions & Bilingual Explanations

Here are realistic interview questions based on this code and how to answer them with analogies and Bengali translations to help you remember them.


1. What does wp_enqueue_style() do?

EN: Loads CSS in a proper, WordPress-managed way.
BN: āĻāϟāĻŋ āϏāĻŋāĻāϏāĻāϏ āĻĢāĻžāχāϞ āϞ⧋āĻĄ āĻ•āϰ⧇ āϏāĻ āĻŋāĻ•āĻ­āĻžāĻŦ⧇, āĻĄā§āĻĒā§āϞāĻŋāϕ⧇āϟ āϞ⧋āĻĄ āĻšāĻ“āϝāĻŧāĻž āĻĨ⧇āϕ⧇ āĻŦāĻžāρāϚāĻžāϝāĻŧāĨ¤

✅ Analogy: Like placing a file in a queue for printing.
🧠 Memory Hook:
E = Enqueue = Enter into Queue


2. Why use esc_url()?

EN: Sanitizes the URL to prevent malicious injections.
BN: URL-āĻ āĻšā§āϝāĻžāĻ•āĻžāϰāĻĻ⧇āϰ āĻ•ā§āώāϤāĻŋāĻ•āϰ āĻ¸ā§āĻ•ā§āϰāĻŋāĻĒā§āϟ āĻĸ⧁āĻ•āϤ⧇ āύāĻž āĻĻ⧇āĻ“āϝāĻŧāĻžāϰ āϜāĻ¨ā§āϝ āĻāϟāĻŋ āĻĒāϰāĻŋāĻˇā§āĻ•āĻžāϰ āĻ•āϰ⧇āĨ¤

✅ Analogy: Washing vegetables before cooking.
🧠 Memory Hook:
Escape harmful input = ESC → esc_url()


3. What is the use of add_action() here?

EN: Hooks your function to run at a specific point (wp_enqueue_scripts).
BN: āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ āϏāĻŽāϝāĻŧ⧇ āĻĢāĻžāĻ‚āĻļāύ āϚāĻžāϞāĻžāύ⧋āϰ āϜāĻ¨ā§āϝ āĻāϟāĻŋ WordPress-āĻ āϝ⧁āĻ•ā§āϤ āĻ•āϰ⧇āĨ¤

✅ Analogy: Like telling your assistant when to serve coffee.
🧠 Memory Hook:
Hook = Trigger Point


4. How are Google Fonts added dynamically?

EN: URL query strings are used to define fonts, weights, and subsets.
BN: āĻĢāĻ¨ā§āϟ, āĻ“āϜāύ, āĻāĻŦāĻ‚ āϏāĻžāĻŦāϏ⧇āϟ āύāĻŋāĻ°ā§āϧāĻžāϰāĻŖ āĻ•āϰāϤ⧇ URL query string āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻž āĻšāϝāĻŧāĨ¤

✅ Analogy: Ordering a pizza with specific toppings.
🧠 Memory Hook:
Query = Instruction to Google Fonts


5. Why use _x() instead of __() or _e()?

EN: _x() allows context-aware translation.
BN: _x() āĻĻāĻŋā§Ÿā§‡ āĻāĻ•āχ āĻļāĻŦā§āĻĻ⧇āϰ āĻŦāĻŋāĻ­āĻŋāĻ¨ā§āύ āĻ…āĻ°ā§āĻĨ context āĻ…āύ⧁āϝāĻžā§Ÿā§€ āĻŸā§āϰāĻžāĻ¨ā§āϏāϞ⧇āϟ āĻ•āϰāĻž āϝāĻžā§ŸāĨ¤

✅ Example: “Post” could mean blog post or mail.
🧠 Memory Hook:
x = eXtra info → Use when context matters


6. What happens if _x() returns 'off'?

EN: The font won’t be loaded, which helps with performance or localization.
BN: _x() 'off' āϰāĻŋāϟāĻžāĻ°ā§āύ āĻ•āϰāϞ⧇ āĻĢāĻ¨ā§āϟ āϞ⧋āĻĄ āĻšāĻŦ⧇ āύāĻž, āĻāϟāĻž āĻ•āĻŋāϛ⧁ āĻĻ⧇āĻļ⧇ āĻĻāϰāĻ•āĻžāϰ āĻšāϤ⧇ āĻĒāĻžāϰ⧇āĨ¤

✅ Use case: Chinese users where Google is blocked.
🧠 Memory Hook:
Translation = ON/OFF switch


7. How to make the font customizable from the WordPress Customizer?

EN: Use get_theme_mod() to dynamically fetch the selected font.
BN: Customizer āĻĨ⧇āϕ⧇ get_theme_mod() āĻĻāĻŋā§Ÿā§‡ āĻĢāĻ¨ā§āĻŸā§‡āϰ āύāĻžāĻŽ dynamically āύ⧇āĻ“ā§ŸāĻž āϝāĻžā§ŸāĨ¤

✅ Analogy: Letting the user choose their outfit before an event.
🧠 Memory Hook:
Customizer = Personalization Panel


8. Why use wp_get_theme()->get('Version') instead of a fixed version?

EN: It automatically updates the version for cache busting.
BN: āĻĨāĻŋāĻŽ āφāĻĒāĻĄā§‡āϟ āĻšāϞ⧇ CSS āϕ⧇āĻļ⧇ āĻĢāĻžāχāϞ āφāϟāϕ⧇ āύāĻž āĻĨāĻžāϕ⧇āĨ¤

✅ Analogy: Putting a version sticker on a product.
🧠 Memory Hook:
Version = Cache Breaker


9. How to load multiple fonts or preload for performance?

EN: Combine multiple family values or use wp_resource_hints for preload.
BN: āĻāĻ•āĻžāϧāĻŋāĻ• āĻĢāĻ¨ā§āϟ āĻāĻ•āϏāĻžāĻĨ⧇ āϝ⧁āĻ•ā§āϤ āĻ•āϰ⧇ āĻŦāĻž preload āĻ•āϰāϞ⧇ āĻĒāĻžāϰāĻĢāϰāĻŽā§āϝāĻžāĻ¨ā§āϏ āĻŦāĻžā§œā§‡āĨ¤

✅ Analogy: Buying multiple tickets in one booking = fewer HTTP requests.
🧠 Memory Hook:
Preload = VIP Access


10. Why use //fonts.googleapis.com instead of https://?

EN: Protocol-relative URLs support both HTTP and HTTPS.
BN: āϏāĻžāχāĻŸā§‡āϰ āĻĒā§āϰ⧋āĻŸā§‹āĻ•āϞ āĻ…āύ⧁āϝāĻžāϝāĻŧā§€ āĻ¸ā§āĻŦāϝāĻŧāĻ‚āĻ•ā§āϰāĻŋāϝāĻŧāĻ­āĻžāĻŦ⧇ āĻ āĻŋāĻ• URL āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻšā§ŸāĨ¤

✅ Analogy: Letting the elevator decide which floor you’re on.
🧠 Memory Hook:
// = Smart Link (protocol auto-adjusts)


📝 Final Summary Table

Question Answer Summary Bengali Keyword
wp_enqueue_style() Adds CSS to WordPress safely āϏāĻ āĻŋāĻ•āĻ­āĻžāĻŦ⧇ CSS āϞ⧋āĻĄ
esc_url() Cleans URL URL āύāĻŋāϰāĻžāĻĒāĻĻ āĻ•āϰāĻž
add_action() Hooks function into WP event āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ āϏāĻŽāϝāĻŧ⧇ āĻĢāĻžāĻ‚āĻļāύ
Dynamic Fonts Fonts via query string āĻĢāĻ¨ā§āϟ URL
_x() Contextual translation āĻ•āύāĻŸā§‡āĻ•ā§āϏāϟ āĻ…āύ⧁āϝāĻžāϝāĻŧā§€ āĻ…āύ⧁āĻŦāĻžāĻĻ
_x() = off Disables font loading āĻĢāĻ¨ā§āϟ āĻŦāĻ¨ā§āϧ
Customizer Fonts Use get_theme_mod() āĻ•āĻžāĻ¸ā§āĻŸā§‹āĻŽāĻžāχāϜāĻžāϰ āĻĢāĻ¨ā§āϟ
Theme Version Cache busting āϕ⧇āĻļ⧇ āϏāĻŽāĻ¸ā§āϝāĻž āϏāĻŽāĻžāϧāĻžāύ
Multiple Fonts Combine in one query āĻāĻ•āĻžāϧāĻŋāĻ• āĻĢāĻ¨ā§āϟ
// URL Protocol-relative HTTP/HTTPS auto

Top comments (0)