0
0
Wordpressframework~20 mins

Functions.php role in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WordPress Functions.php Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary role of functions.php in a WordPress theme?

Choose the best description of what the functions.php file does in a WordPress theme.

AIt controls the layout and structure of the website pages.
BIt contains the CSS styles for the theme's appearance.
CIt manages the database connections for WordPress.
DIt stores the theme's custom PHP functions and hooks to extend WordPress functionality.
Attempts:
2 left
💡 Hint

Think about where you add custom code to change how WordPress works without editing core files.

component_behavior
intermediate
2:00remaining
What happens if you add a function in functions.php that conflicts with a plugin function?

Consider you add a function named custom_login_message() in your theme's functions.php file, but a plugin also defines a function with the same name. What will happen when WordPress runs?

AThe theme's function will override the plugin's function without error.
BThe plugin's function will override the theme's function without error.
CPHP will throw a fatal error because the function is declared twice.
DWordPress will ignore both functions and use a default login message.
Attempts:
2 left
💡 Hint

Think about how PHP handles two functions with the same name loaded in the same request.

📝 Syntax
advanced
2:00remaining
Which code snippet correctly adds a custom menu location in functions.php?

Choose the correct code to register a new menu location called 'Footer Menu' in functions.php.

Aadd_theme_support('footer-menu', 'Footer Menu');
Bregister_nav_menus(array('footer-menu' => 'Footer Menu'));
Cregister_nav_menu('footer-menu', 'Footer Menu');
Dadd_menu_location('footer-menu', 'Footer Menu');
Attempts:
2 left
💡 Hint

Look for the function that registers multiple menu locations using an array.

lifecycle
advanced
2:00remaining
When is functions.php loaded during WordPress page load?

At what point in the WordPress loading process is the functions.php file of the active theme loaded?

AImmediately after WordPress core files load, before any template files.
BAfter the header template is loaded but before the content.
COnly when a plugin calls it explicitly.
DAfter the footer template is loaded.
Attempts:
2 left
💡 Hint

Think about when theme functions need to be available for hooks and templates.

🔧 Debug
expert
2:00remaining
Why does adding this code to functions.php cause a white screen?

Given this code added to functions.php:

add_action('init', 'my_custom_function');
function my_custom_function() {
  echo 'Hello World!';
}

Why might this cause a white screen (blank page) when loading the site?

AOutputting text during 'init' breaks HTTP headers, causing a fatal error and blank page.
BThe function name conflicts with a core WordPress function causing a fatal error.
CThe 'init' hook does not exist, so the function never runs and causes a blank page.
DEchoing text is allowed on 'init', so this code does not cause a white screen.
Attempts:
2 left
💡 Hint

Consider when headers are sent and what happens if output is sent too early.