WordPress plugin admin notifications not working on custom admin pages

I’m building a WordPress plugin and having trouble with admin notifications on my custom admin page. I tried two different approaches but neither works properly.

First attempt - Manual HTML:

<div id="notification" class="updated below-h2 notice is-dismissible">
    <p><?php echo $alert_text; ?></p>
    <button type="button" class="notice-dismiss">
        <span class="screen-reader-text">Close this notification.</span>
    </button>
</div>

The dismiss button doesn’t work because there’s no click event handler attached.

Second attempt - Using admin_notices hook:

function show_admin_notification() {
    ?>
    <div class="notice notice-info is-dismissible">
        <p>Innovation distinguishes between a leader and a follower ~ Steve Jobs</p>
    </div>
    <?php
}
add_action('admin_notices', 'show_admin_notification');

This displays notifications everywhere in the admin area. On default WordPress pages the dismiss functionality works fine, but on my custom admin page the close button doesn’t respond to clicks.

I read somewhere that admin notifications only work properly on built-in WordPress admin pages. However, I’ve seen other plugins that successfully implement dismissible notifications on their custom pages.

How can I make admin notifications work correctly on custom plugin pages?

try checking your page’s setup. remember to enqueue the dismissal scripts! like, add wp_enqueue_script( 'common' ); to your page. I had the same issue and this worked for me!

WordPress doesn’t auto-load the dismiss functionality on custom admin pages. You’ve got to manually enqueue the admin scripts and styles that handle notice dismissal. In your custom admin page callback, add wp_enqueue_script('wp-admin'); and wp_enqueue_style('wp-admin'); before rendering your content. Also make sure you’re calling do_action('admin_notices'); in the right spot - usually right after the page header but before your main content. I ran into this exact issue building a custom dashboard for a client. The notices showed up but clicking dismiss did nothing until I properly enqueued those core WordPress scripts. Without them, the JavaScript handlers for dismissal just aren’t there on your custom pages.