Skip to content

Instantly share code, notes, and snippets.

@torounit
Created May 11, 2013 17:51
Show Gist options
  • Save torounit/5560793 to your computer and use it in GitHub Desktop.
Save torounit/5560793 to your computer and use it in GitHub Desktop.
WordPressマルチサイトで、body_classに"site-hoge"を出力するクラス。
<?php
class Ms_Body_Class {
public function __construct() {
add_filter( "body_class", array( $this, "body_class" ));
}
public function get_blog_path() {
$blog_details = get_blog_details($GLOBALS['blog_id']);
$blog_path = trim( $blog_details->path, "/" );
return $blog_path;
}
public function body_class( $classes ) {
$blog_path = $this->get_blog_path();
if(!$blog_path) {
$blog_path = "main";
}
$classes[] = "site-".$blog_path;
return $classes;
}
}
new Ms_Body_Class();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment