My need is to check if a page is subpage of a page (with ID).
I try to get this code working but it doesn't.
function is_child($pageID) {
global $post;
echo $post->post_parent; // display the right ID!
if( is_page() && $post->post_parent == $pageID ) {
return true;
} else {
return false;
}
}
It returns always false while $post->post_parent returns the right ID!
Testing code (which always returns no while $post->$post_parent echoes the good ID in the function):
if(is_child(2310)) {
echo 'yes';
} else {
echo 'no';
}
This function takes place in my functions.php file and its purpose is to load CSS through a condition statement (load a particular CSS file if page is X or child of X).
This code can be found on many sites around there but was produced in 2012-2013.
Thanks a lot for any help.
Sources of unworking codes : https://bavotasan.com/2011/is_child-conditional-function-for-wordpress/ https://www.kevinleary.net/wordpress-is_child-for-advanced-navigation/