Sequence of important actions run by wordpress
WordPress runs a variety of actions during a typical request lifecycle, triggering specific hooks that developers can use to execute custom code at various stages. Understanding the sequence of these actions can greatly help in theme and plugin development. Below is a simplified sequence of important actions that WordPress fires in a typical page request. This sequence focuses on front-end requests rather than admin pages.
Initial Setup
muplugins_loaded
: Fires once all must-use plugins are loaded.registered_taxonomy
: Fires after a taxonomy is registered.registered_post_type
: Fires after a post type is registered.
Setup Environment
plugins_loaded
: All plugins are loaded. It's the first action hooked to after plugins are loaded.sanitize_comment_cookies
: Sanitizes the comment cookies if they're set.setup_theme
: Fires before the theme is loaded.unload_textdomain
: Fires before unloading translations of a text domain.load_textdomain
: Fires after loading the translations of a text domain.after_setup_theme
: The theme's functions.php file is invoked. It's time to add theme support and define functions.
Set Up Query
init
: WordPress core features are set up; custom post types and taxonomies should be registered by now.widgets_init
: Registers widgets. Sidebars can also be registered at this point.register_sidebar
: Fires once for each sidebar being registered.wp_register_sidebar_widget
: Fires once a sidebar widget has been registered.wp_loaded
: WP Object is set up, and this hook is fired.
Parse Request
parse_request
: Fires before the WordPress query is set up.send_headers
: Sends HTTP headers.
Query Posts
pre_get_posts
: Fires before the query is executed.posts_selection
: Fires once the post query has been executed.
Load Template
template_redirect
: Before deciding which template to load.wp_enqueue_scripts
,admin_enqueue_scripts
, andlogin_enqueue_scripts
: Used to enqueue scripts and styles.wp_enqueue_scripts
is for the front end.
The Loop
loop_start
: Fires just before The Loop begins.the_post
: Runs during The Loop to set up post data.loop_end
: Fires just after The Loop ends.
Footer and Shutdown
wp_footer
: Used to hook into the footer, for enqueuing scripts, adding HTML, etc.get_footer
: Fires before the footer template file is loaded.shutdown
: Executes just before PHP shuts down execution.
Remember, this sequence is simplified and focuses on the frontend; admin pages and AJAX requests have their sequences. Moreover, between these actions, there are numerous other actions and filters that WordPress also executes, which developers can hook into for more specific needs or to alter the default behavior.
Published on: Mar 11, 2024, 04:13 AM