Show message on wordpress admin dashboard

I have created a form. On success of the form, I am redirecting the user the their dashboard. Now, I want to be able to show a success message/notice on the dashboard.

What is the convention to show such messages ?

Related posts

Leave a Reply

1 comment

  1. When you redirect the user to the admin dashboard pass on a GET variable named “success_notice”, for example. So you get a URL like this: /wp-admin/index.php?success_notice=1.

    With that setup, just add the code that shows the success message on the dashboard only if that GET variable is set.

    add_action('admin_notices', 'wpse75629_admin_notice');
    
    function wpse75629_admin_notice()
    {
        global $pagenow;
    
        // Only show this message on the admin dashboard and if asked for
        if ('index.php' === $pagenow && ! empty($_GET['success_notice']))
        {
            echo '<div class="updated"><p>Your success message!</p></div>';
        }
    }