Be Studios

Intercontinental Design Firm

This is our knowledge center. Enjoy!

WordPress Multisite: adding blogname to body_class()

WordPress Multisite is very cool and helpful but brings many functions and classes poorly planned and documented; one of them is related to get_blog_details(), where I need to rescue the name of the site to add it in the as an ID to generate new styles depending on the site. To fix it, I found a filter that extend body_class() and add the site name as slug (websafe):

    //adding blogname to body_class()
    add_filter('body_class', 'multisite_body_classes');
    function multisite_body_classes($classes) {
       $id = get_current_blog_id();
       $slug = strtolower(str_replace(' ', '-', trim(get_bloginfo('name'))));
       $classes[] = $slug;
       $classes[] = 'site-id-'.$id;
       return $classes;



Ben: Dude... freaking sweet and SUPER handy little filter!!! Saved me coming up with it myself. muchos gracias!