How to customize the settings saved message in WordPress plugins?

I’m developing a WordPress plugin with a settings page. Everything’s working fine, but I want to add more functionality. When you save the settings, the page refreshes and displays a message at the top that says ‘Settings saved.’ I’d like to insert some custom text into that message box.

Is there any way to adjust this message? I checked the WordPress documentation but didn’t find a clear solution. Has anyone managed to customize it, perhaps using a filter or action hook?

I’m relatively new to plugin development, so any advice or code example would be greatly appreciated. Thanks in advance for the help!

You’re in luck! There’s actually a straightforward way to customize that settings saved message. Look into the ‘admin_notices’ action hook. You can use it to display your own custom message after settings are saved.

Here’s a basic example of how you might implement this:

add_action('admin_notices', 'my_custom_admin_notice');

function my_custom_admin_notice() {
    if (isset($_GET['settings-updated'])) {
        echo '<div class=\"notice notice-success is-dismissible\"><p>Your custom message here!</p></div>';
    }
}

Just add this to your plugin’s main file. You can customize the message and even add more complex logic if needed. Remember to sanitize any user input if you’re including dynamic content in your message. Hope this helps with your plugin development journey!

hey there, i’ve dealt with this before! you can use the ‘settings_errors’ function to customize that message. just add something like this to your code:

add_action(‘admin_notices’, ‘my_custom_message’);
function my_custom_message() {
settings_errors(‘my_messages’);
}

then use add_settings_error() to set ur custom message. hope this helps!

I’ve been down this road before, and there’s actually a neat trick you can use to customize that settings saved message. The key is to leverage the ‘admin_init’ hook in combination with the add_settings_error() function.

Here’s what worked for me:

add_action(‘admin_init’, ‘custom_settings_message’);

function custom_settings_message() {
if (isset($_GET[‘settings-updated’])) {
add_settings_error(‘custom_messages’, ‘custom_message’, ‘Your settings have been saved and optimized!’, ‘updated’);
}
}

This approach gives you full control over the message content and lets you tailor it to your plugin’s specific needs. You can even add conditional logic to display different messages based on which settings were changed.

Just remember to clear any existing messages first if you want your custom one to be the only one shown. It’s been a game-changer for my plugin UIs.