Make WordPress Core

Opened 7 weeks ago

#43963 new enhancement

Add admin body class for multisite blog ID and network admin context

Reported by: dryanpress Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Administration Keywords:
Focuses: administration, multisite Cc:


In multisite, it'd be great to have an admin body class to safely scope CSS to specific blogs (i.e. blog-2 or network-admin) available by default. I often filter admin_body_class to add these.

One situation where I often use this is conditional override of the text Site Title in the Admin Bar with a logo -- but only if the logo exists. PHP can certainly be used to check context before printing conditional CSS, but the body class adds a safe, client-side scope and clear approach for avoiding in-admin style collisions.


if ( ! empty( $logo ) ) {
	body.blog-<?php echo esc_attr( $site_id ); ?> li#wp-admin-bar-site-name > a.ab-item:first-of-type,
	body.blog-<?php echo esc_attr( $site_id ); ?> #wpadminbar .ab-top-menu > li#wp-admin-bar-site-name.menupop:hover > .ab-item:first-of-type,
	body.blog-<?php echo esc_attr( $site_id ); ?> #wpadminbar .ab-top-menu > li#wp-admin-bar-site-name.menupop.hover > .ab-item:first-of-type {
		font-size: 0; // safely hide default text
	        background-image: url("<?php echo esc_url( $logo ); ?>");
		background-size: <?php echo esc_html( $logo_width ); ?>;
		background-position: center;
		background-repeat: no-repeat;
		min-width: 120px;

Change History (0)

Note: See TracTickets for help on using tickets.