All active snippets are executed on the plugins_loaded
hook. That means that they will run as soon as all of the active plugins have been loaded into the site.
Here's where that takes place in relation to a number of other common WordPress actions:
muplugins_loaded
– all must-use plugins are loaded.plugins_loaded
– all active plugins are loaded.- all active snippets are loaded.
setup_theme
– just before the current theme is loaded.- current theme's
functions.php
file is evaluated. after_setup_theme
– just after the current theme is loaded.set_current_user
– the userdata for the currently logged-in person is set up.init
– most of WordPress has loaded; just before the page's content is sent to the browser.wp_loaded
– WordPress has been fully loaded.pre_get_posts
– just before the active query is run (front-end only).wp
– WordPress environment has been fully set up.
If you want to delay your snippet to run on a later hook, you can do so using the add_action
function. Here's an example:
add_action( 'init', function () { // snippet code goes here } );