Inspiration For Creative Minds
Home » Labs » WordPress Return ID if Parent Page Exists  

Filed under Labs

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.

function is_subpage() {
    global $post;
    if ( is_page() && $post->post_parent ) {
        return $post->post_parent;
    } else {
        return false;
It's only fair to share...Share on Google+Tweet about this on TwitterShare on Facebook

Posts you may like: