Skip to content

Instantly share code, notes, and snippets.

@chasereeves
Created January 31, 2012 22:27
Show Gist options
  • Save chasereeves/1713449 to your computer and use it in GitHub Desktop.
Save chasereeves/1713449 to your computer and use it in GitHub Desktop.
Add page classes to body tag: wp_page wp_post singular is_has_child single_author
//=========================================================== ADD PAGE BODY CLASS TO PAGES
function custom_page_bodyclass($classes) {
// add 'no-js' to body. Javascript in custom/js/script.js removes this when JS is active
$classes[] = 'no-js';
if ( is_page() ) { $classes[] = 'wp_page'; }
if ( is_single() ) { $classes[] = 'wp_post'; }
// is_singular is true for is_single(), is_page() or is_attachment()
if ( is_singular() ) { $classes[] = 'singular'; }
// is_has_child is true for a parent or a child page
if ( function_exists( 'is_has_child' ) && is_has_child() ) { $classes[] = 'is_has_child'; }
// is_multi_author is true when there's more than one author on the site
if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) { $classes[] = 'single_author'; }
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment