follow mejoin mesubscribe

Page Depth Body Class for WordPress

Assumes that your page depth is how the pages are organized in the page hierarchy, not custom menu hierarchy

 * Add page depth body class.
 * Adds depth-x body class
 * @author Jen Baumann
 * @link
function depth_body_class($classes) {
	global $post;
	if (is_page()) {
	    if ($post->post_parent)	{
        	$ancestors = get_post_ancestors($post);
			$depth = count($ancestors) + 1;
        } else {
        	$depth = 1;
        $classes[] = 'depth-' . $depth;
	return $classes;
About Jennifer Baumann

I am an avid horseback rider, animal lover, and freelance designer. I love working with WordPress and Genesis and work for Copyblogger Media as a Technical Support Advocate.

Dream Whisper Designs is Powered by Genesis

StudioPress Premium WordPress Themes

Genesis empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go. It's that simple - start using Genesis now!

Take advantage of the 6 default layout options, comprehensive SEO settings, rock-solid security, flexible theme options, cool custom widgets, custom design hooks, and a huge selection of child themes ("skins") that make your site look the way you want it to. With automatic theme updates and world-class support included, Genesis is the smart choice for your WordPress website or blog.