This tutorial provides the way to conditionally target a selected parent page and its subpages in WordPress. while working with Genesis Framework.
TYEP 1
WordPress offers is_tree() option to create a function and then output a small snippet based on Page ID.
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath global $post; // load details about this page if(is_page()&&($post->post_parent==$pid||is_page($pid))) return true; // we're at the page or at a sub page else return false; // we're elsewhere };
Usage:
add_action('genesis_before_content', 'custom_tree_child', 15); function custom_tree_child'() { if ( is_tree(533) ) { echo "This is a child page"; } }
Text -> This is a child page <- will output on subpages of a Parent Page with ID 533. You must change it to match with your Parent Page ID.
TYPE 2
This is a similar approach but works directly.
// if a page is a child of a certain page add_action('genesis_before_content', 'custom_parent_child_pages', 15); function custom_parent_child_pages() { global $post; if ( $post->post_parent == '533' ) { //is_page( 'about' ) || '2' == $post->post_parent ) echo "This is a child page"; } }
Change Number to match with your Parent Page ID.
Reference:
https://codex.wordpress.org/Conditional_Tags
https://developer.wordpress.org/reference/functions/is_page/