Make WordPress Core

Opened 6 years ago

Last modified 6 years ago

#43963 new enhancement

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

Reported by: dryanpress's profile dryanpress Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Administration Keywords: 2nd-opinion
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 ) ) {
	?><?php echo esc_attr( $site_id ); ?> li#wp-admin-bar-site-name > a.ab-item:first-of-type,<?php echo esc_attr( $site_id ); ?> #wpadminbar .ab-top-menu > li#wp-admin-bar-site-name.menupop:hover > .ab-item:first-of-type,<?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 (2)

This ticket was mentioned in Slack in #core-multisite by dryanpress. View the logs.

6 years ago

#2 @jeremyfelt
6 years ago

  • Keywords 2nd-opinion added

Hi @dryanpress, thanks for opening this ticket and taking time to discuss in office hours today.

I'm in the middle on whether or not this belongs as part of core or should remain as plugin/theme code. There is a likelihood that it would be useful for people customizing the admin.

As discussed in chat, .network-admin exists for the network admin and .wp-admin exists for all admin pages. We can use that to determine site vs network. The larger question is how to identify an individual site. .site-# would be simple, though also seems like something that may belong as a front-end class or per-row in the sites list table. I suggested .site-#-admin, though I'm not sure if that's confusing.

I'm hoping some others will chime in with feedback here around naming. :)

Note: See TracTickets for help on using tickets.