I want to show the admin bar on my single.php page ONLY when the actual author of the post is on the page. I took this article as a reference and was able to make the admin bar visible on single.php pages only, but I also want to add a condition to hide it to non-author viewers. https://second-cup-of-coffee.com/hiding-the-wordpress-admin-bar-on-certain-pages/
And this is the code I tried on my functions.php:
function my_theme_hide_admin_bar($bool) {
$logged_in_user = wp_get_current_user();
$logged_in_user_id = $logged_in_user->ID;
if ( ! is_single() && $logged_in_user_id !== get_the_author_meta('ID') ) :
return false;
else :
return $bool;
endif;
}
add_filter('show_admin_bar', 'my_theme_hide_admin_bar');
However, the admin bar still shows when I view a post from another author.