WordPress Return ID if Parent Page Exists

In WordPress development sometimes you want to know the ID of the parent page, in such case you can use the bellow WP snippet which will you return the ID of the parent page if the page has a parent. Open your function.php and add the following code to it, now take a test run on localhost, it will work.

<?php 
function is_subpage() {
    global $post;
    if ( is_page() && $post->post_parent ) {
        return $post->post_parent;
    } else {
        return false;
    }
}
?>

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