Show the Site Time in the Admin Bar
Displays the current time in the site's timezone in the admin bar, which helps when scheduling posts from another timezone.
Opens WPIDE on
Code
add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {
if ( ! current_user_can( 'edit_posts' ) ) {
return;
}
$timezone = wp_timezone_string();
$wp_admin_bar->add_node( array(
'id' => 'wpide-site-time',
'parent' => 'top-secondary',
'title' => esc_html( wp_date( get_option( 'time_format' ) ) ),
'href' => current_user_can( 'manage_options' ) ? admin_url( 'options-general.php#timezone_string' ) : false,
'meta' => array( 'title' => 'Site time (' . $timezone . ')' ),
) );
}, 1 );
Notes
The time is set when the page loads; it does not tick.
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.