How to Echo Depth of Current Page in WordPress

Are you looking for a WordPress code which displays the depth of current page, then here is a code snippet which will shows dept in integer (eg: mane page 0, sub pages 1, 2, etc..).Just copy it to your functions.php in theme folder.

 * This function will display current dept of wordpress pages in integer format
function wp_current_page_depth(){
	global $wp_query;
	$object = $wp_query->get_queried_object();
	$parent_id  = $object->post_parent;
	$depth = 0;
	while($parent_id > 0){
		$page = get_page($parent_id);
		$parent_id = $page->post_parent;
 	return $depth;

Related posts:

Partner with Us

We are providing an exclusive partnership offer to individuals and companies who are interested in setting up their own web design & development company. For more information about how to partner with us, please contact us