If WordPress is being loaded from an external PHP file by including wp-blog-header.php
and the WP_USE_THEMES
constant is set to false
, the template_redirect
hook will not be fired. This is important because template_redirect
is how the Toolbar is initialized on the front end. Taking a look at default-filters.php
we can see where the Toolbar is initialized:
...
// Admin Bar
// Don't remove. Wrong way to disable.
add_action( 'template_redirect', '_wp_admin_bar_init', 0 ); // <-- initialize Toolbar
add_action( 'admin_init', '_wp_admin_bar_init' ); // <-- initialize Toolbar
add_action( 'before_signup_header', '_wp_admin_bar_init' ); // <-- initialize Toolbar
add_action( 'activate_header', '_wp_admin_bar_init' ); // <-- initialize Toolbar
add_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
add_action( 'in_admin_header', 'wp_admin_bar_render', 0 );
...
A function can be added via plugin or theme to trigger the initialization of the Toolbar:
function wpse240134_wp_admin_bar_init() {
_wp_admin_bar_init();
}
add_action( 'init', 'wpse240134_wp_admin_bar_init' );
Note that _wp_admin_bar_init()
is considered an internal function for WordPress so use it at your own risk.
See also Admin Bar (Toolbar) not showing on custom PHP file that loads WordPress.
More details on loading WP using an external PHP file: What is the correct way to use wordpress functions outside wordpress files?