Essential Hooks Reference
4 min read Quiz at the end
Know these hooks: init, wp_enqueue_scripts, save_post, pre_get_posts, the_content filter.
Essential WordPress Hooks
| Hook | Type | When |
|---|
| init | Action | After WP loads, before headers |
| wp_enqueue_scripts | Action | Queue scripts/styles |
| the_content | Filter | Modify post content |
| save_post | Action | After post saved |
| pre_get_posts | Action | Modify main query |
| wp_head | Action | Inside head tag |
| wp_footer | Action | Before end of body |
| admin_menu | Action | Add admin menu items |
// pre_get_posts -- modify main query without new WP_Query
function modify_home_query($query) {
if (!is_admin() && $query->is_main_query() && is_home()) {
$query->set('posts_per_page', 12);
$query->set('post_type', ['post','news']);
}
}
add_action('pre_get_posts', 'modify_home_query');