Skip to content

Instantly share code, notes, and snippets.

@cezarpopa
Last active November 14, 2015 12:49
Show Gist options
  • Select an option

  • Save cezarpopa/f9a4aeceded937945fa1 to your computer and use it in GitHub Desktop.

Select an option

Save cezarpopa/f9a4aeceded937945fa1 to your computer and use it in GitHub Desktop.
add url / slug from page/pages to body WordPress
/**
* Adds custom classes to the array of body classes.
* Based @Underscores.me
* @param array $classes Classes for the body element.
* @return array
*/
function ks_body_classes( $classes ) {
// Adds a class of group-blog to blogs with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
global $wp_query;
$page = '';
if (is_front_page() ) {
$page = 'home';
} elseif (is_page()) {
$page = $wp_query->query_vars["pagename"];
}
if ($page)
echo 'class= "'. $page . '"';
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
return $classes;
}
add_filter( 'body_class', 'ks_body_classes' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment