Home » Wordpress » WordPress Get parent page ID if exists

This is a great little wordpress snippet that will let you return the ID of the parent page if the page has a parent in wordpress

1
2
3
4
5
6
7
8
9
10
11
12
<?php
 
function is_subpage() {
    global $post;
    if ( is_page() && $post->post_parent ) {
        return $post->post_parent;
    } else {
        return false;
    }
}
 
?>

Array ( [0] => Wordpress, Wordpress Tip and Tricks )

Leave a comment

0 Comments.

Leave a Reply

You must be logged in to post a comment.