So I'm using WordPress in a 'themeless' manner, i.e. not using a "blog" template. My site files are in the root directory (not in the theme folder), and WordPressis installed in its own /wordpress/ directory. The only thing my theme exists for is customization of the back-end, including re-branding and custom post types. (I'm basically avoiding plug-ins and widgets and doing a bespoke implementation of WordPress)

With this set-up, is there a way I can get the admin bar to display when my clients view the front-end pages like it normally does?

NOTE: I've tried adding wp_head() and wp_footer() to no avail. I think this might have something to do with my custom file structure.

require_once 'wordpress/wp-load.php';

Maybe you have to remove some things from the footer-file (e.g. Powered By WordPress). With var_dump( $wp_actions ); you can see which actions was executed (a list of action hooks). And with var_dump( $wp_filter['wp_footer'] ); you can see which actions are registred for the specific hook (here wp_footer).

  • Hey thanx for the answer! The thing is though I've done this and I still get no admin bar. I've added wp_footer at many different points of my script and I get absolutely no render at all. Mind you, I'm in the top-level directory and not in the THEME directory. – Spartacus May 3 '13 at 14:19
  • I tested it in the opposit way. WordPress in the root, the file with adminbar in a subfolder. This works great. I think it is a path problem. Wp setup ABSPATH to yourdomain.tld/wordpress/ and it seems, that everything below this path (yourdomain.tld/) does not exists for WP. I try something different, maybe it works for you. – Ralf912 May 3 '13 at 15:42

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() {
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.