X

Return ID if Parent Page Exists

Do you want to return the ID of the parent page if parent page exists? You may have sub pages or child pages with parent ID. Add the following code to the functions.php file of your WordPress theme to return ID if parent page exists.

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

We hope this code helped you return ID if parent page exists. You may also want to check out our guide on the 15 do’s and don’ts of effective WordPress theming.

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!