0
0
Wordpressframework~20 mins

Menus and navigation in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WordPress Menus Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this WordPress menu registration code?

Consider this code snippet in a WordPress theme's functions.php file:

function register_my_menu() {
  register_nav_menu('header-menu', __('Header Menu'));
}
add_action('init', 'register_my_menu');

What does this code do when the theme is active?

Wordpress
function register_my_menu() {
  register_nav_menu('header-menu', __('Header Menu'));
}
add_action('init', 'register_my_menu');
ARegisters a single navigation menu location called 'Header Menu' available in the admin menu settings.
BAutomatically creates a menu with items named 'Header Menu' in the front-end.
CRemoves all existing menus and replaces them with 'Header Menu'.
DRegisters multiple menu locations including 'Header Menu' and 'Footer Menu'.
Attempts:
2 left
💡 Hint

Think about what register_nav_menu does versus creating menu items.

📝 Syntax
intermediate
2:00remaining
Which option correctly outputs a WordPress menu in a theme template?

You want to display a menu assigned to the 'header-menu' location in your theme template. Which code snippet will correctly output the menu?

A<?php get_nav_menu('header-menu'); ?>
B<?php wp_nav_menu('header-menu'); ?>
C<?php display_menu('header-menu'); ?>
D<?php wp_nav_menu(array('theme_location' => 'header-menu')); ?>
Attempts:
2 left
💡 Hint

Look for the correct function and parameter format to display menus.

🔧 Debug
advanced
2:00remaining
Why does this WordPress menu not display any items?

Given this code in a theme template:

<?php wp_nav_menu(array('theme_location' => 'footer-menu')); ?>

And the admin menu settings show no menu assigned to 'footer-menu'. What is the reason no menu items appear?

Wordpress
<?php wp_nav_menu(array('theme_location' => 'footer-menu')); ?>
ANo menu is assigned to the 'footer-menu' location, so nothing displays.
BThe function <code>wp_nav_menu</code> is deprecated and won't work.
CThe 'footer-menu' location is misspelled in the code.
DMenus only display if registered with <code>register_nav_menus</code>, not <code>register_nav_menu</code>.
Attempts:
2 left
💡 Hint

Check the admin menu assignment for the location.

state_output
advanced
2:00remaining
What is the output of this WordPress menu walker customization?

Consider this custom walker class snippet:

class My_Walker extends Walker_Nav_Menu {
  function start_el(&$output, $item, $depth=0, $args=null, $id=0) {
    $output .= '<li>' . strtoupper($item->title) . '</li>';
  }
}

wp_nav_menu(array('theme_location' => 'header-menu', 'walker' => new My_Walker()));

What will the menu items look like when rendered?

Wordpress
class My_Walker extends Walker_Nav_Menu {
  function start_el(&$output, $item, $depth=0, $args=null, $id=0) {
    $output .= '<li>' . strtoupper($item->title) . '</li>';
  }
}

wp_nav_menu(array('theme_location' => 'header-menu', 'walker' => new My_Walker()));
AThe code will cause a fatal error due to incorrect walker method signature.
BMenu items will appear normally without any change.
CMenu items will be list items with titles in uppercase letters.
DMenu items will be hidden because the walker does not call parent methods.
Attempts:
2 left
💡 Hint

Look at how the walker modifies the output string.

🧠 Conceptual
expert
2:00remaining
Which statement best describes WordPress menu locations and menus?

Choose the statement that correctly explains the relationship between menu locations and menus in WordPress.

AMenus define where in the theme links appear; menu locations are collections of links created by users.
BMenu locations are theme-defined placeholders; menus are user-created sets of links assigned to these locations.
CMenu locations and menus are the same; both refer to the actual list of links shown on the site.
DMenus are registered in the theme code; menu locations are created by users in the admin panel.
Attempts:
2 left
💡 Hint

Think about who creates menu locations and who creates menus.