0

I am using multisite and have made inactive one of the sites. I would like a way to add a class to the body tag of inactive sites so that I can in turn, use that class to add a note for admin to see from the front-end that the site is indeed inactive. Can the functions file be used to do this perhaps?

0

Yes, you can use the body_class filter. If all the sites use the same theme, you can get away with putting this in functions.php (in a child theme so your code doesn't get overwritten when the theme is updated), but if any sites have a different theme, you'll need to put it into a custom plugin (perhaps a MU plugin).

<?php
add_filter('body_class', 'wpse_299000_body_class');
function wpse_299000_body_class() {
    // check if current subsite is inactive, deleted, archived, or spammed
    $is_inactive = ms_site_check();
    // value will come back either true or false
    if($is_inactive == true) {
        // add your desired class to <body> - this example adds .inactive
        $classes[] = 'inactive';
    }
    // always return classes so none are taken away
    return $classes;
}
?>

You can also remove classes if needed.

| improve this answer | |
  • Excellent. I am using the same theme for all sites so this will be great. I’m actually very surprised there was no answer anywhere else for this; seems it would be pretty handy for others. Thank you. – Toasterdroid Mar 27 '18 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.