Admin & Dashboard PHP Intermediate

Add a Site Notes Widget to the Dashboard

Give your team a shared notes box on the dashboard for logins, reminders and handover notes, editable by administrators.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 28 lines
add_action( 'wp_dashboard_setup', function (): void {
	wp_add_dashboard_widget( 'nahnu_site_notes', 'Site notes', function (): void {
		$notes = (string) get_option( 'nahnu_site_notes', '' );

		echo $notes ? wp_kses_post( wpautop( $notes ) ) : '<p>No notes yet.</p>';

		if ( current_user_can( 'manage_options' ) ) {
			?>
			<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
				<input type="hidden" name="action" value="nahnu_save_site_notes">
				<?php wp_nonce_field( 'nahnu_site_notes' ); ?>
				<textarea name="nahnu_site_notes" rows="6" style="width:100%"><?php echo esc_textarea( $notes ); ?></textarea>
				<p><button type="submit" class="button button-primary">Save notes</button></p>
			</form>
			<?php
		}
	} );
} );

add_action( 'admin_post_nahnu_save_site_notes', function (): void {
	if ( ! current_user_can( 'manage_options' ) ) {
		wp_die( 'Not allowed.' );
	}
	check_admin_referer( 'nahnu_site_notes' );
	update_option( 'nahnu_site_notes', wp_kses_post( wp_unslash( $_POST['nahnu_site_notes'] ?? '' ) ), false );
	wp_safe_redirect( admin_url( 'index.php' ) );
	exit;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

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.

Every site has things the team needs to remember: which plugin handles redirects, when the SSL renews, who to call about hosting. This snippet adds a notes box to the dashboard that everyone can read and administrators can edit.

How it works

wp_add_dashboard_widget() registers the widget. It shows the saved notes, with line breaks turned into paragraphs, to everyone who can see the dashboard. Administrators also get a textarea and Save button.

The form posts to admin-post.php, where the handler checks the user can manage options, verifies the nonce, cleans the text with wp_kses_post() so only safe HTML is kept, and saves it as a non-autoloaded option.

Things to watch

  • Don’t store passwords here. Anyone who can see the dashboard, and anyone with database access, can read the notes. Use a password manager for credentials.
  • Basic HTML like links and bold text is allowed.

How to test it

Open the dashboard, type a note and click Save notes. It should appear above the form, and an editor should see it without the form.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only