I've been using the following functions (updating IDs manually) to group parent & child pages into an array, which I then use in an if/else statement to present content depending on whether or not the current page is in that array. Examples below:
function id_array_function() {
$array = array(
10, // Example Parent ID
12, // Example Child ID
14 // Example Child ID
);
return $array;
}
function content_placement_function() {
if( is_page( id_array_example() ) ) {
// If current page is in array, do this
}
else {
// Otherwise, do this
}
}
Ideally, I'd like to create a reusable function which I can plug any page name into (avoiding IDs due to issues with local/production installs having different page IDs), and return an array of both the parent and any child page names for use elsewhere, such as:
if( is_page( id_array_function('About') ) ) {
// Function would return array as ('About', 'Our Company', 'Careers', 'etc...')
// If current page is in array, do this
}
I've attempted this with wp_list_pages (could not return, only echo), and get_posts/get_terms (both returned empty arrays). If anyone has a pre-existing snippet or an idea as to how I could achieve the reusable function, I'd be massively appreciative of the help.
==========
EDIT: Working answer from Krzysiek below. Possible alternative option on CSS Tricks (targeting IDs): https://css-tricks.com/snippets/wordpress/if-page-is-parent-or-child/