Inspiration For Creative Minds
Home » Labs » How to Echo Depth of Current Page in WordPress  

Filed under Labs

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;
It's only fair to share...Share on Google+Tweet about this on TwitterShare on Facebook

Posts you may like: