Get Current Page Depth

Is there a function in WordPress to check the current page depth like is_child(), is_grandchild() or a number for unlimited depth? I could’nt find any so I created one. It is a recursive function which means that it calls itself until it’s done.

Put the following code to the functions.php in your WordPress theme folder. Source