When you’ve sub pages or child pages with parent ID in WordPress, you may want to check for the parent page ID for your sub pages or child pages.
Instructions: Add the following code to the functions.php file of your WordPress theme to return ID if parent page exists.
function is_subpage() { global $post; if ( is_page() && $post->post_parent ) { return $post->post_parent; } else { return false; } }
You may also enjoy do’s and don’ts of effective WordPress theming.
Comments Leave a Reply