Independent Editorial DeskWordPress Releases, Builds, and Operations
Back to Archive
Implementation Notes

WordPress add_settings_error Example: Show Settings Feedback Correctly

Use add_settings_error and settings_errors so WordPress settings pages show accurate success, warning, and validation feedback.

Published

April 26, 2026

Reading Time

2 min read

Updated

April 26, 2026

Settings validation notices in WordPress showing clear error and success feedback flow.
Build PatternImplementation Notes

Implementation Notes

Extension points, code paths, and implementation choices that should survive contact with production.

Best For

WordPress developers, agencies, and technical teams building custom plugin or theme functionality with cleaner operational defaults.

Primary Topics

Implementation Notes

Editorial Focus

Build Pattern: Extension points, code paths, and implementation choices that should survive contact with production. Updated on April 26, 2026.

Full Report

Last reviewed: April 26, 2026

Settings pages feel unfinished when validation fails silently or success feedback is inconsistent. WordPress already provides a native message pipeline for this through add_settings_error() and settings_errors(), but many plugins still fall back to ad hoc notices or raw query-string flags.

This guide shows how to attach Settings API feedback to the actual sanitize flow so users see the right success, warning, or error message after a save.

Add feedback in the sanitize callback

<?php
register_setting(
	'vulnwp_general',
	'vulnwp_api_base_url',
	array(
		'sanitize_callback' => 'vulnwp_validate_api_base_url',
	)
);

function vulnwp_validate_api_base_url( $value ) {
	$value = esc_url_raw( $value );

	if ( '' === $value ) {
		add_settings_error(
			'vulnwp_api_base_url',
			'vulnwp_api_base_url_empty',
			'API base URL cannot be empty.',
			'error'
		);

		return get_option( 'vulnwp_api_base_url', '' );
	}

	add_settings_error(
		'vulnwp_api_base_url',
		'vulnwp_api_base_url_saved',
		'API base URL saved successfully.',
		'success'
	);

	return $value;
}

Putting the feedback inside the sanitize callback keeps the message tied to the actual validation outcome instead of guessing later whether the save should be considered valid.

Render the messages on the page

function vulnwp_render_settings_page() {
	?>
	<div class=\"wrap\">
		<h1>VulnWP Settings</h1>
		<?php settings_errors( 'vulnwp_api_base_url' ); ?>
		<form action=\"options.php\" method=\"post\">
			<?php
			settings_fields( 'vulnwp_general' );
			do_settings_sections( 'vulnwp_general' );
			submit_button();
			?>
		</form>
	</div>
	<?php
}

WordPress can display many setting messages automatically after submission, but explicit placement with settings_errors() keeps the page layout predictable.

Choose the right message type

Modern WordPress supports error, success, warning, and info. Use them deliberately instead of reporting everything as an error.

Production checklist

  • Add feedback inside the sanitize callback for the relevant setting.
  • Return a safe fallback value when validation fails.
  • Render the messages with settings_errors() in a predictable location.
  • Use message types that match the real outcome.
  • Keep error codes stable so notices stay easy to trace.
  • Avoid hand-rolled query-string success banners when the Settings API already covers the workflow.

Common mistakes

  • Displaying generic success banners even when validation failed. That confuses operators immediately.
  • Not returning a fallback value. Settings fields can end up blank unexpectedly.
  • Mixing unrelated settings into the same error bucket. Messages should map cleanly to the field or group.
  • Using custom admin notices for every Settings API save. Native settings feedback is already available.
  • Skipping explicit rendering. Message placement becomes inconsistent across custom pages.

Related reading

If the setting itself is registered manually, pair this with the Settings API guide. If the saved value is a URL, combine it with the esc_url article so validation and storage rules stay aligned.

References and further reading

Popular Guides

Popular WordPress guides to read next.

These articles connect recurring production concerns: implementation details, updates, troubleshooting, recovery paths, and operational cleanup.

Continue Reading

More from the archive.

Diagnostic dashboard scene representing a WordPress Site Health review before major updates.
01Build Pattern
Implementation Notes

Build Pattern

Extension points, code paths, and implementation choices that should survive contact with production.

May 21, 2026 · 3 min read

WordPress Site Health Check Before Major Updates: What to Review First

A pre-update WordPress Site Health checklist covering loopbacks, connectivity, debug settings, and environment readiness.

Structured data and route review scene representing permalink validation after a WordPress migration.
02Build Pattern
Implementation Notes

Build Pattern

Extension points, code paths, and implementation choices that should survive contact with production.

May 21, 2026 · 3 min read

WordPress Permalink Checklist After Migration: Catch URL Problems Early

A post-migration WordPress permalink checklist for checking rewrite rules, post URLs, archives, and redirect noise.

Technical media workspace representing image preparation and optimization before upload to WordPress.
03Build Pattern
Implementation Notes

Build Pattern

Extension points, code paths, and implementation choices that should survive contact with production.

May 21, 2026 · 3 min read

WordPress Image Optimization Checklist: What to Fix Before Upload

A practical WordPress image optimization checklist covering dimensions, compression, formats, and Media settings before upload.