Add class to parent page and class to sub-child page
In WordPress, you can add a class to be applied anywhere in the web document, for example appending a class to the body tag, if the current page is a parent page or not.
Place the below if condition anywhere in your theme files; don’t insert it in functions.php
$current_page = get_page($post->ID);
if($current_page->post_parent > 0) {
echo 'parent-page';
} else {
echo 'no-parent-page';
}
?>
This will output parent-page on parent pages and no-parent-page on a sub-child page.
