What is the purpose of admin menu pages in WordPress?
Admin menu pages let you add new sections or pages in the WordPress dashboard for managing settings or content related to your plugin or theme.
Click to reveal answer
beginner
Which WordPress function is used to add a new top-level admin menu page?
The function add_menu_page() is used to create a new top-level menu item in the WordPress admin sidebar.
Click to reveal answer
intermediate
What parameters does add_menu_page() require?
It requires: page title, menu title, capability (who can see it), menu slug (unique ID), callback function to display content, icon URL or dashicon, and position in the menu.
Click to reveal answer
intermediate
How do you add a submenu page under an existing admin menu in WordPress?
Use the add_submenu_page() function, specifying the parent slug, page title, menu title, capability, menu slug, and callback function.
Click to reveal answer
beginner
Why is it important to check user capabilities when adding admin menu pages?
Checking capabilities ensures only authorized users can see or access the menu pages, keeping the admin area secure and organized.
Click to reveal answer
Which function adds a new top-level admin menu page in WordPress?
Aadd_menu_page()
Badd_admin_page()
Ccreate_menu_page()
Dregister_menu_page()
✗ Incorrect
The correct function to add a top-level admin menu page is add_menu_page().
What does the 'capability' parameter control in admin menu functions?
AThe icon shown in the menu
BWho can see and access the menu page
CThe position of the menu item
DThe URL of the menu page
✗ Incorrect
The 'capability' parameter controls which user roles can see and access the menu page.
Which parameter in add_menu_page() defines the function that outputs the page content?
Amenu_slug
Bicon_url
Cpage_title
Dcallback
✗ Incorrect
The 'callback' parameter is the function that outputs the content of the admin page.
To add a submenu page under 'Settings', which parent slug should you use?
Aedit.php
Btools.php
Coptions-general.php
Dadmin.php
✗ Incorrect
The parent slug for the Settings menu is 'options-general.php'.
What happens if you do not check user capabilities when adding admin menu pages?
AAll users, including unauthorized ones, can see the menu page
BThe menu page will not show at all
CThe menu icon will be missing
DThe menu page will load faster
✗ Incorrect
Without capability checks, unauthorized users might see or access admin pages, risking security.
Explain how to add a new top-level admin menu page in WordPress and what each parameter means.
Think about what you want the menu to show and who should see it.
You got /6 concepts.
Describe the difference between add_menu_page() and add_submenu_page() in WordPress admin menus.
One creates main menu items, the other adds items inside them.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the add_menu_page function in WordPress?
easy
A. To register a new user role
B. To add a submenu item under an existing menu
C. To enqueue scripts and styles in the admin area
D. To add a new top-level menu page to the WordPress admin dashboard
Solution
Step 1: Understand the function purpose
add_menu_page is used to create a new top-level menu in the WordPress admin dashboard.
Step 2: Compare with other options
Adding submenu items uses add_submenu_page, user roles are registered differently, and scripts/styles are enqueued with other functions.
Final Answer:
To add a new top-level menu page to the WordPress admin dashboard -> Option D
Quick Check:
add_menu_page adds top-level menu [OK]
Hint: Remember: add_menu_page = top-level menu [OK]
Common Mistakes:
Confusing add_menu_page with add_submenu_page
Thinking it registers user roles
Mixing it with script enqueue functions
2. Which of the following is the correct way to hook add_menu_page in WordPress?
easy
A. add_action('admin_menu', 'my_menu_function');
B. add_action('init', 'my_menu_function');
C. add_filter('admin_menu', 'my_menu_function');
D. add_action('wp_head', 'my_menu_function');
Solution
Step 1: Identify the correct hook for admin menus
The admin_menu action hook is the correct place to add admin menu pages.
Step 2: Check other hooks
init runs too early, wp_head is for front-end, and add_filter is incorrect for this purpose.
Final Answer:
add_action('admin_menu', 'my_menu_function'); -> Option A
Quick Check:
Use admin_menu hook for admin menus [OK]
Hint: Use admin_menu hook to add admin menus [OK]
Common Mistakes:
Using init hook which is too early
Using add_filter instead of add_action
Hooking into front-end hooks like wp_head
3. What will happen if you run this code in your plugin?
B. Nothing happens because the callback function is missing
C. A new top-level menu named 'My Plugin' appears in admin, showing 'Hello Admin!' when clicked
D. The menu appears but clicking it shows a blank page
Solution
Step 1: Analyze the add_menu_page parameters
The code adds a menu titled 'My Plugin' with capability 'manage_options' and a callback that echoes 'Hello Admin!'.
Step 2: Understand the callback behavior
When the menu is clicked, the callback runs and outputs 'Hello Admin!'. No errors occur because capability and callback are valid.
Final Answer:
A new top-level menu named 'My Plugin' appears in admin, showing 'Hello Admin!' when clicked -> Option C
Quick Check:
Valid add_menu_page with callback shows output [OK]
Hint: Callback echoes content on menu page click [OK]
Common Mistakes:
Assuming callback is missing
Confusing capability with missing parameter
Expecting blank page without callback
4. Identify the error in this code snippet:
add_action('admin_menu', 'register_my_menu');
function register_my_menu() {
add_menu_page('Sample', 'Sample', 'manage_options');
}
medium
A. Callback function is missing but required
B. Missing menu slug parameter in add_menu_page
C. Capability 'manage_options' is invalid
D. Wrong hook used for adding menu page
Solution
Step 1: Check add_menu_page parameters
The function call has only three parameters: page title, menu title, and capability.
Step 2: Verify required parameters
The menu slug parameter is missing, which is required as the fourth argument.
Final Answer:
Missing menu slug parameter in add_menu_page -> Option B
Quick Check:
add_menu_page needs menu slug [OK]
Hint: add_menu_page needs 4+ parameters including slug [OK]
Common Mistakes:
Forgetting the menu slug argument
Assuming callback is mandatory (optional)
Using wrong hook instead of admin_menu
5. You want to add a top-level admin menu page visible only to users who can edit posts, with the menu slug 'custom-editor'. Which code snippet correctly achieves this?