Use wp init hook to call other hooks?

In general: Yes, wait for a dedicated hook to start your own code. Never just throw an object instance into the global namespace. But init is rarely necessary.

You hook in as late as possible. If your first code runs on wp_head do not use an earlier hook. You can even cascade hooks:

add_action( 'wp_head', 'first_callback' );

function first_callback()
{
    // do something
    // then
    add_action( 'wp_footer', 'second_callback' );
}

Regarding the init hook: Use wp_loaded instead. That runs after init and after ms_site_check() was called. This way you avoid to run your plugin on an invalid sub site in a multi-site installation. Everything else is the same.

Leave a Comment