If the parent of the page is ID (number)?

I have an if statement verifying the page id using the following:

<?php if ( is_page(10) ) { ?> 

How can I do something like if the page parent is 10?

+4
source share
3 answers

try something like this

 global $post; if ($post->post_parent == 10) { echo "parent id is 10"; } 
+16
source

Get the current page object, then get its parent id:

 global $wp_query; $currentPage = get_page($wp_query->get_queried_object_id()); if (is_page($currentPage['post_parent'])) { } 
0
source
 $id = wp_get_post_parent_id( get_the_id() ); 

Now $id has parent page $id

0
source

All Articles