Skip to content

Instantly share code, notes, and snippets.

@hofmannsven
Last active April 3, 2018 23:51
Show Gist options
  • Save hofmannsven/7592304 to your computer and use it in GitHub Desktop.
Save hofmannsven/7592304 to your computer and use it in GitHub Desktop.
Using a dynamic admin body class within WordPress to distinguish between light or dark admin interface.
<?php
add_filter( 'admin_body_class', 'admin_interface_version_body_class' );
function admin_interface_version_body_class( $classes ) {
// check wp_version
if ( version_compare( $GLOBALS['wp_version'], '3.8-alpha', '>' ) ) {
$classes .= 'dark-admin-ui'; // new admin interface
} else {
$classes .= 'light-admin-ui'; // old admin interface
}
return $classes;
}
?>
<?php
add_filter( 'admin_body_class', 'admin_interface_version_body_class' );
function admin_interface_version_body_class( $classes ) {
// check wp_version
if ( version_compare( $GLOBALS['wp_version'], '3.8-alpha', '>' ) ) {
$classes .= 'dark-admin-ui'; // new admin interface
} else {
// check admin_color
if ( get_user_option( 'admin_color' ) === 'mp6' ) {
$classes .= 'dark-admin-ui'; // updated old admin interface
} else {
$classes .= 'light-admin-ui'; // old admin interface
}
}
return $classes;
}
?>
<?php
add_filter( 'admin_body_class', 'admin_interface_version_body_class' );
function admin_interface_version_body_class( $classes ) {
// check wp_version
if ( version_compare( $GLOBALS['wp_version'], '3.8-alpha', '>' ) ) {
// check admin_color
if ( get_user_option( 'admin_color' ) === 'light' ) {
$classes .= 'light-admin-ui'; // custom new admin interface
} else {
$classes .= 'dark-admin-ui'; // new admin interface
}
} else {
$classes .= 'light-admin-ui'; // old admin interface
}
return $classes;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment