Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm serving a different header in Wordpress depending what section you are within the site, 'residential' , 'business' or other by using the following code. Although i need to extend it to work with grandchildren as well, so another level down.

<?php
/*
Template Name: Package
*/ 
if (is_page('business') || $post->post_parent=="17")
{
get_header('business');
}
else if (is_page('residential') || $post->post_parent=="19")
{
get_header('residential');
}
else 
{
get_header();
}
?>
share|improve this question

1 Answer 1

get_ancestors() will return the full parent page ID hierarchy for a given page ID which you could check against.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.