The generate_hook_element_display
allows us to bypass the Display Rules, so we can enable or disable an Element under our own conditions.
For example, if we want to assign a specific hook to Author Tom only:
add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
if ( 10 === $element_id && is_author( 'Tom' ) ) {
$display = true;
}
return $display;
}, 10, 2 );
Another useful example is to set the hook to display on the parent page and all the child pages automatically:
add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
global $post;
if ( 1180 === $element_id && ( is_page() && $post->post_parent == '415' ) ) {
$display = true;
}
return $display;
}, 10, 2 );
You need to replace 1180
with the ID of your Element, and 415
with the ID of the parent page.