What’s the point of hooking register_nav_menu to "init" rather than calling it directly?

The standard method of registering a menu with WordPress consists in adding this to functions.php:

function register_menu() {
  register_nav_menu('main_menu', 'Main Menu');
}
add_action('init', 'register_menu');

But why not simply calling register_nav_menu() from functions.php without hooking anything?

register_nav_menu('main_menu', 'Main Menu');

It works fine too so why bother?

Read more here: What’s the point of hooking register_nav_menu to "init" rather than calling it directly?

Leave a Reply

Your email address will not be published. Required fields are marked *