Skip to content

Instantly share code, notes, and snippets.

@Lego2012
Created February 24, 2023 08:18
Show Gist options
  • Save Lego2012/ffc3d765104779fc9467e21982d3a70d to your computer and use it in GitHub Desktop.
Save Lego2012/ffc3d765104779fc9467e21982d3a70d to your computer and use it in GitHub Desktop.

Just a quick way of hiding the Wordpress admin bar without having to go into the User Settings or turning it off completely. Just add ?nowp to the URL and it's gone. Easy preview without the menu. Especially useful when you have fixed elements like a header which can end up behind this bar

<?php

add_action('wp', 'hide_admin_bar_if_nowp');

function hide_admin_bar_if_nowp() {
    if (isset($_GET['nowp'])) {
        add_filter('show_admin_bar', '__return_false');
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment