WordPress Return ID if Parent Page Exists
In WordPress development sometimes you want to know the ID of the parent page, in such case you can use the bellow WP snippet which will you return the ID of the parent page if the page has a parent. Open your function.php and add the following code to it, now take a test run on localhost, it will work.
<?php function is_subpage() { global $post; if ( is_page() && $post->post_parent ) { return $post->post_parent; } else { return false; } } ?> |