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' );
đ¯ 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)