0
0
Wordpressframework~20 mins

Common action hooks in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WordPress Hooks Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when the 'init' action hook is triggered?
In WordPress, the 'init' action hook is one of the earliest hooks triggered during page load. What is the typical behavior when this hook runs?
AIt runs after WordPress has finished loading but before any headers are sent, allowing you to register custom post types and taxonomies.
BIt runs after the theme template is loaded and outputs the page content.
CIt runs only when a user logs in and initializes user session data.
DIt runs after the footer is rendered to enqueue scripts for the next page.
Attempts:
2 left
💡 Hint
Think about when you want to register custom post types or taxonomies in WordPress.
state_output
intermediate
2:00remaining
What is the output of this code using 'wp_footer' hook?
Consider this WordPress code snippet added to functions.php:
add_action('wp_footer', function() { echo '

Footer message

'; });

What will appear on the page?
Wordpress
add_action('wp_footer', function() { echo '<p>Footer message</p>'; });
AThe text will appear at the top of the page before the header.
BThe text '<p>Footer message</p>' will appear just before the closing </body> tag in the HTML.
CNothing will appear because 'wp_footer' is not a valid hook.
DThe text will appear inside the <head> section of the HTML.
Attempts:
2 left
💡 Hint
Remember where the 'wp_footer' hook is placed in the theme template.
📝 Syntax
advanced
2:00remaining
Which option correctly adds a function to the 'admin_menu' action hook?
You want to add a custom admin menu page in WordPress. Which code snippet correctly hooks your function to 'admin_menu'?
Aadd_action('admin_menu', function my_custom_menu() { add_menu_page('Title', 'Menu', 'manage_options', 'slug', 'callback'); });
Badd_action('admin_menu', my_custom_menu()); function my_custom_menu() { add_menu_page('Title', 'Menu', 'manage_options', 'slug', 'callback'); }
C} ;)'kcabllac' ,'guls' ,'snoitpo_eganam' ,'uneM' ,'eltiT'(egap_unem_dda { )(unem_motsuc_ym noitcnuf ;)'unem_motsuc_ym' ,'unem_nimda'(noitca_dda
Dadd_action('admin_menu', 'my_custom_menu'); function my_custom_menu() { add_menu_page('Title', 'Menu', 'manage_options', 'slug', 'callback'); }
Attempts:
2 left
💡 Hint
Check how the function name is passed to add_action and if parentheses are used.
🔧 Debug
advanced
2:00remaining
Why does this 'save_post' hook not trigger the function?
Given this code in functions.php:
add_action('save_post', 'save_custom_data');
function save_custom_data() {
  error_log('Saving data');
}

Why might 'Saving data' not appear in the error log when a post is saved?
Wordpress
add_action('save_post', 'save_custom_data');
function save_custom_data() {
  error_log('Saving data');
}
AThe function name is misspelled in the add_action call.
BThe error_log function is disabled in the server configuration.
CThe 'save_post' hook passes parameters, but the function does not accept any, causing it not to run.
DThe 'save_post' hook only triggers on pages, not posts.
Attempts:
2 left
💡 Hint
Check the function signature and parameters expected by the hook.
🧠 Conceptual
expert
2:00remaining
Which hook is best to enqueue scripts and styles properly in WordPress?
You want to add custom JavaScript and CSS files to your WordPress theme or plugin. Which action hook should you use to enqueue these assets correctly?
Awp_enqueue_scripts
Binit
Ctemplate_redirect
Dwp_head
Attempts:
2 left
💡 Hint
Think about the hook designed specifically for adding scripts and styles on the front end.