Add Page Ancestor body_class()

Follow this WordPress Codex example and this support forum comment, add this into your header.php file and style the resulting body class accordingly:


$class = '';
/* is it a page */
if( is_page()) { 
	global $post;

	$parent = array_reverse(get_post_ancestors($post->ID));
	$first_parent = get_page($parent[0]);
	$class = $first_parent->post_name;

<body <?php body_class($class);?>>


Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.