# Site ID and Path Classes on the Body Tag

> Adds classes such as site-3 and site-shop to the body tag on every network site, so one shared stylesheet can target individual sites.

- Type: PHP
- Runs: Frontend only
- Category: [Multisite](https://wpide.com/library/category/multisite/)
- Tags: body-class, css, sites
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/ms-body-class-site/

## Code

```php
if ( ! is_multisite() ) {
    return;
}

add_filter( 'body_class', function ( $classes ) {
    $site      = get_site();
    $classes[] = 'site-' . get_current_blog_id();
    $classes[] = is_main_site() ? 'site-main' : 'site-sub';

    $slug = trim( (string) ( $site ? $site->path : '' ), '/' );
    if ( '' === $slug && $site ) {
        $slug = strtok( $site->domain, '.' );
    }
    if ( '' !== $slug ) {
        $classes[] = 'site-' . sanitize_html_class( $slug );
    }

    return $classes;
} );
```

## Notes

""

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Site ID and Path Classes on the Body Tag" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
