Snippets: Display Custom Sidebar For Specific Page & Child Pages

// Display the 'my_custom_sidebar' for the page with ID of 2 and all children of this page
function myprefix_custom_sidebar_display( $sidebar ) {
	if ( is_page() && ( is_page( '2' ) || '2' == wp_get_post_parent_id() ) ) {
		$sidebar = 'my_custom_sidebar';
	}
	return $sidebar;
}
add_filter( 'wpex_get_sidebar', 'myprefix_custom_sidebar_display' );
All PHP snippets should be added via a child theme's functions.php file.