Home > Tips & Tricks > Check Page is Parent or Child in WordPress

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 😉

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

Leave a Comment