Created
November 26, 2013 18:35
-
-
Save aaronranard/7663469 to your computer and use it in GitHub Desktop.
WordPress: is a child page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Child page conditional | |
* @ Accept's page ID, page slug or page title as parameters | |
*/ | |
function is_child( $parent = '' ) { | |
global $post; | |
$parent_obj = get_page( $post->post_parent, ARRAY_A ); | |
$parent = (string) $parent; | |
$parent_array = (array) $parent; | |
if ( in_array( (string) $parent_obj['ID'], $parent_array ) ) { | |
return true; | |
} elseif ( in_array( (string) $parent_obj['post_title'], $parent_array ) ) { | |
return true; | |
} elseif ( in_array( (string) $parent_obj['post_name'], $parent_array ) ) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment