Hooks (Actions and Filters) Flashcards
Q: What are hooks in WordPress?
A: Hooks are functions that allow developers to modify or add functionality to WordPress without modifying core files.
Q: What are the two types of hooks in WordPress?
A: Action hooks and filter hooks.
Q: What is an action hook?
A: A hook that allows you to add or execute custom code at specific points in the WordPress lifecycle.
Q: What is a filter hook?
A: A hook that allows you to modify data before it is output or saved.
Q: How do you add a function to a hook?
A: Using the add_action() or add_filter() functions.
Q: What is the syntax for add_action()?
add_action( ‘hook_name’, ‘callback_function’, $priority, $accepted_args );
Q: What is the purpose of the init action hook?
A: It is triggered after WordPress has finished loading but before headers are sent.
Q: What is the wp_head action hook used for?
A: To add custom code to the <head> section of a theme.
Q: What is the wp_footer action hook used for?
A: To add custom code to the footer of a theme.
Q: What is the purpose of the admin_init action hook?
A: It is triggered when the WordPress admin dashboard is initialized.
Q: What is the template_redirect action hook?
A: It runs before WordPress determines which template to load.
Q: What is the save_post action hook used for?
A: To execute custom code when a post is saved.
Q: What is the wp_enqueue_scripts action hook?
A: It is used to enqueue styles and scripts for the front end.
Q: What is the admin_enqueue_scripts action hook?
A: It is used to enqueue styles and scripts for the admin dashboard.
Q: What is the widgets_init action hook?
A: It is used to register custom widget areas.
Q: What is the syntax for add_filter()?
add_filter( ‘hook_name’, ‘callback_function’, $priority, $accepted_args );