In functions.php of a theme makes a call to show_admin_bar(false)
which hides admin bar in front end:
if (!is_admin())
{
wp_deregister_style( 'bp-admin-bar' );
if ( function_exists( 'show_admin_bar' ) )
{
show_admin_bar( false );
remove_action( 'bp_init', 'bp_core_load_buddybar_css' );
}
}
I want to make admin bar appear in front end for the admin
users. To do this, I added the following code to a plugin:
add_action('plugins_loaded', 'show_admin_bar_to_admins', 100);
function show_admin_bar_to_admins()
{
if (current_user_can('manage_options')) {
show_admin_bar(true);
}
}
But this call didn’t make a difference. I put 100
as the priority value such in order to make this function to be called later than the call inside functions.php
. But it didn’t make a difference.
Is there a way to make a function call inside a plugin to be executed later than the call inside functions.php
.
First off: This Theme is so doing it wrong. One should not simply stuff plain calls in functions.php files. Those should be wrapped and hook. Best to
after_setup_theme()
. You could btw try the same hook.I think the best way to show or hide the admin bar is by hooking into
show_admin_bar
filter, and specifying the conditions you need in the filter function:This will take care of adding necessary scripts and styles for the admin bar as well.