Hide admin bar on certain post type

Don’t hack your WordPress core. It’s overriden after every upgrade (plugins do exist for some reason).

You can solve your problem in this way:

1) Open your single.php.
2) Define

<?php 
function hideAdminBar ($post_id)
{
    if (get_post_type ($post_id) == 'post')
    {
        add_filter ('show_admin_bar', '__return_false');

        /* For removing the top blank space. */
        echo '<style type="text/css" media="screen">
            html { margin-top: 0px !important; }
            * html body { margin-top: 0px !important; }
            </style>';
    }
} 
?> 

3) Inside The Loop, call this function right after the while condition. Like this:

<?php while ( have_posts() ) : the_post();?>

    <?php hideAdminBar (get_the_ID ()); ?>
    /* etc. */

<?php endwhile; ?>

Hope this solves your issue.

Leave a Comment