• Dear WP users

    I would like to propose that WordPress includes <body> tag class blog-<blog_id> on network installations when one calls body_class() function.

    I am currently adding it via my theme, but I think it would make sense for the class to be added by default, allowing pages/posts templates differentiation from one blog to the next. This is what I do for those interested,

    // Add specific CSS class by filter
    add_filter( 'body_class', 'network_blog_id_class_name' );
    function network_blog_id_class_name( $classes ) {
            $blogID = get_current_blog_id(;
    	$classes[] = 'blog-'.$blogID;
    	return $classes;
    }

    I have also toyed with the idea of putting an extra attribute into the <body> tag with the id of the current blog,

    <body blog="1" class="blog-1....">

    this would allow one to leverage the CSS3 attribute selectors.

    Any thoughts?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    That sounds like something that would be better put in an MU plugin, rather than a theme.

    This also feels like a very unique one-off. If you consider that themes can’t possibly know for whom they’re written or what site they’ll be used on, this is only beneficial to people who home-brew their own themes and want to use one theme for all sites with per-site customizations. Also on a Multisite network, there’s no way for a non-network admin to be able to edit the theme.

    Thus only people who are trying to build a one-theme-fits all setup will benefit. It can’t be easily leveraged to all sites since they can’t edit any of the CSS.

    If a per-site needs to customize, then they should use something like Jetpack CSS (or other tools, I keep saying I want to build a file editor type version of that…) or they let the site admin apply the tweak just like you did ?? But for general WP things, it’s not really going to work right because the people who need it can’t take advantage of it without making child themes anyway.

    Thread Starter Aurovrata Venet

    (@aurovrata)

    Dear Mika

    thanks for your inputs. However, I am inclined to say that the points your raised are debatable. The bottom line is wether or not child-sites can be custom-themes by their admins…

    Also on a Multisite network, there’s no way for a non-network admin to be able to edit the theme.

    This is often the case with simple themes such as the ones distributed with WP installs. However, many themes (all of the Elegant Themes for example) give you provision to add custom CSS within the Dashboard itself, even in child-sites. You also have many plugins that can give direct/indirect access to theme modification, so I think this point is moot.

    We do a lot of projects for multi-site networks (conference/university, multi-resort businesses, multi-brand companies) where the single DB installation is a blessing. However, it is important at times to have the ability to target a group of websites. The above can easily be integrated with a plugin, and we do this now. However, in the extrapolation of the current logic to tag pages in the <body> tag for post, page, single, archive and so on, it would make for a rather nice and logical extension in the the future development of WP Network installs.

    Add this as a plugin OR to your themes functions.php ??

    //*** Body Classes
    	function add_blog_id_body_class($classes) {
    
    	$classes[] = 'blog-'.get_current_blog_id();
    	// return the modified $classes array
    	return $classes;
    	}
    
    	// add my custom class via body_class filter
    	add_filter('body_class','add_blog_id_body_class');

    For some extra body class I wrote this up ?? I originally wrote this as a plugin for the admin area, but it comes in handy for the front-end as well.

    Add Blog ID / User Role to Body Class

    Thread Starter Aurovrata Venet

    (@aurovrata)

    Dear Jarod

    yeah, sure we use this already (it is in my original post if you haven’t read it as yet), the point I was trying to raise was that a systematic blog_id class in the pages of Network WP sites seems a logical inclusion ‘out-of-the-box’ in the sane way page_ids are included.

    Ahh, I see. I only noticed there was a variance from what I had. It is essentially the same. Thank you.

    As originally suggested (in addition to functions.php inclusion) you could write it as a mu-plugin or a network activated plugin / as needed per site. That would provide a network wide blog-ID class, or easy plugin activation, which is what I believe you implied.

    Thanks again.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Suggestiong for body_class to inlcude blog ID’ is closed to new replies.