While the recipe's original code displays a pop-up dialog on every single page of a website, it may be better to show it only on specific pages, such as the front page, to avoid over-exposition. To accomplish this, we can move the two add_action calls inside of an action hook callback and check whether the visitor is making a request to see the front page before loading our scripts:
add_action( 'template_redirect', 'ch9pud_template_redirect' );
function ch9pud_template_redirect() {
if ( is_front_page() ) {
add_action( 'wp_enqueue_scripts', 'ch9pud_load_scripts' );
add_action( 'wp_footer', 'ch9pud_footer_code' );
}
}
A similar technique can be used by substituting the is_front_page function with the is_page( 'id_title_or_slug' ) function, which checks whether the current page numeric ID, title, or post slug matches the value that it receives as an argument. In that situation, a plugin configuration page could allow users to easily select one or more pages on which the dialog should appear.