How to query if is Page, Child of Page, or Grandchild of Page

Say you want to show a certain menu depending on what page you’re on. So if I have in my navigation a link that has Children and Grandchildren, this is how you check to see what page you’re on, if it’s a child or even a Grandchild of a certain page.

Do stuff if is page:

Do stuff if is a child of a page: (My products page’s id=17 and I’m viewing, Products > “Cars”)

Do stuff if is a Grandchild of a page: (My products page’s id=17 and I’m viewing, Products > Cars > “Red Cars”)

Do stuff if is a Page, or a Child of that page or a Grandchild of that page: (All together now)

Leave a Reply

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

26 + = 31