Skip to content

Instantly share code, notes, and snippets.

@wp-kitten
Created February 25, 2015 09:56
Show Gist options
  • Save wp-kitten/bd190ea2bcf703cdf0ad to your computer and use it in GitHub Desktop.
Save wp-kitten/bd190ea2bcf703cdf0ad to your computer and use it in GitHub Desktop.
Admin bar menu entry to confirm the website is running on localhost
<?php
/*
* Add a new entry in the admin bar that will display the "LOCL INSTANCE" text.
* I find this approach especially useful when running remote websites on the
* localhost server and, because the URL is the same, it's hard to tell which
* is which. This new menu entry will confirm this is a local instance.
*
* Usage: Add this code to your theme's functions.php file
*
* Note: Do not forget to remove it when you upload changes to the remote server
*/
add_action('admin_bar_menu', 'wpk_local_adminbar_notice', 100);
function wpk_local_adminbar_notice($wp_admin_bar){
$args = array(
'id' => 'custom-notice-local',
'title' => 'LOCAL INSTANCE',
'meta' => array(
'class' => 'custom-notice-class'
)
);
$wp_admin_bar->add_node($args);
}
add_action('admin_head', 'wpk_local_adminbar_notice_styles', 100);
add_action('wp_head', 'wpk_local_adminbar_notice_styles', 100);
function wpk_local_adminbar_notice_styles(){ ?>
<style type="text/css" id="wpk_local_adminbar_notice_styles">
#wpadminbar .ab-top-menu .custom-notice-class,
#wpadminbar .ab-top-menu .custom-notice-class:hover,
#wpadminbar .ab-top-menu .custom-notice-class:active,
#wpadminbar .ab-top-menu .custom-notice-class:focus { background: #ffa500 !important; }
#wpadminbar .ab-top-menu .custom-notice-class:hover div,
#wpadminbar .ab-top-menu .custom-notice-class:active div,
#wpadminbar .ab-top-menu .custom-notice-class:focus div,
#wpadminbar .ab-top-menu .custom-notice-class div { color: #000; cursor: default; background: #ffa500; }
#wpadminbar .ab-top-menu .custom-notice-class:hover div { color: #000 !important; }
</style>
<?php }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment