Bird
0
0

Which code snippet correctly attaches a function named 'custom_function' to the 'init' action hook in WordPress?

easy📝 Syntax Q3 of 15
Wordpress - WordPress Hooks System
Which code snippet correctly attaches a function named 'custom_function' to the 'init' action hook in WordPress?
Aadd_filter('init', 'custom_function');
Badd_action('init', 'custom_function');
Cadd_action('custom_function', 'init');
Dadd_filter('custom_function', 'init');
Step-by-Step Solution
Solution:
  1. Step 1: Identify hook type

    'init' is an action hook, so use add_action.
  2. Step 2: Correct syntax

    add_action('hook_name', 'function_name'); is the correct format.
  3. Final Answer:

    add_action('init', 'custom_function'); -> Option B
  4. Quick Check:

    Use add_action for actions [OK]
Quick Trick: Use add_action for actions, add_filter for filters [OK]
Common Mistakes:
  • Using add_filter for action hooks
  • Swapping hook and function names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes