Show a warning at the top of the editor when someone opens the page set as your homepage.
function nahnu_editing_front_page(): bool {
$id = absint( $_GET['post'] ?? 0 );
return $id && $id === (int) get_option( 'page_on_front' );
}
// Block editor.
add_action( 'enqueue_block_editor_assets', function (): void {
if ( nahnu_editing_front_page() ) {
wp_add_inline_script(
'wp-notices',
"wp.data.dispatch( 'core/notices' ).createWarningNotice( 'You are editing the homepage. Changes appear on the front page as soon as you update.', { isDismissible: true } );"
);
}
} );
// Classic editor.
add_action( 'admin_notices', function (): void {
$screen = get_current_screen();
if ( $screen && 'post' === $screen->base && ! $screen->is_block_editor() && nahnu_editing_front_page() ) {
echo '<div class="notice notice-warning"><p><strong>You are editing the homepage.</strong> Changes appear on the front page as soon as you update.</p></div>';
}
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
The homepage is the most visible page on a site and the easiest to break. A clear warning when someone opens it makes them slow down before clicking Update.
The page set under Settings → Reading as “Your homepage displays” is stored in the page_on_front option. When the post being edited matches it, the snippet shows a warning.
The block editor doesn’t show classic admin notices, so for it the snippet adds a small script that creates a native editor notice through core/notices. The classic editor gets a standard admin notice.
Open the page set as your homepage in the editor. A yellow warning should appear at the top.