Skip to content

Instantly share code, notes, and snippets.

@intelliweb
Created April 14, 2013 18:08
Show Gist options
  • Save intelliweb/5383629 to your computer and use it in GitHub Desktop.
Save intelliweb/5383629 to your computer and use it in GitHub Desktop.
WP: dynamically add CSS class to body tag based on website domain. Useful when your using the same theme on all sites, but want to alter some styling (e.g. background) on some sites.
<?php
// Add custom CSS class to <body> tag
add_filter('body_class','intw_body_class');
function intw_body_class($classes) {
$url = get_bloginfo('url');
if( ($url == 'http://siteA.com') || ($url == 'http://devserver.com/siteA') ) {
$classes[] = 'siteA';
return $classes;
} elseif ( ($url == 'http://siteB.com') || ($url == 'http://devserver.com/siteB') ) {
$classes[] = 'siteB';
return $classes;
} elseif ( ($url == 'http://siteC.com') || ($url == 'http://devserver.com/siteC') ) {
$classes[] = 'siteC';
return $classes;
} elseif ( ($url == 'http://siteD.com') || ($url == 'http://devserver.com/siteD') ) {
$classes[] = 'siteD';
return $classes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment