Check Page is Parent or Child in WordPress

Hello friends, in this trick I will show you the core function of WordPress to check whether the page is parent or child.

There are built-in WordPress core functions that you can use to make a condition to check the details of the page and see whether it’s a parent page or a child page.

Check Page

To check whether the given ID is a page or not, you can use the is_page() function of WordPress. It will check the provided ID is the ID of the page and then you can make conditions accordingly.

Check Child Page

To check that the current is the child of the certain page, you can use the $post global object to make a condition with “post_parent” key.

The above condition will tell you that the current page is the child of page ID 7.

Being Tricky 😉

Leave a Reply

Your email address will not be published. Required fields are marked *