Environment Name in the Browser Tab Title
Prefixes browser tab titles with [LOCAL], [DEV] or [STAGING] for logged-in users on non-production sites, in the admin and on the front end, so open tabs are easy to tell apart.
Opens WPIDE on
Code
$wpide_env_label = function () {
$labels = array( 'local' => 'LOCAL', 'development' => 'DEV', 'staging' => 'STAGING' );
$environment = wp_get_environment_type();
return isset( $labels[ $environment ] ) && is_user_logged_in() ? '[' . $labels[ $environment ] . '] ' : '';
};
add_filter( 'admin_title', function ( $title ) use ( $wpide_env_label ) {
return $wpide_env_label() . $title;
}, 99 );
add_filter( 'document_title_parts', function ( $parts ) use ( $wpide_env_label ) {
if ( $wpide_env_label() && isset( $parts['title'] ) ) {
$parts['title'] = $wpide_env_label() . $parts['title'];
}
return $parts;
}, 99 );
Notes
Visitors and the production site see normal titles.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.