Display admin notice only on main dashboard page

You can try the following:

function my_admin_notice() { ?>
    <div class="updated">
        <p><?php _e( 'some message', 'my-text-domain' ); ?></p>
    </div>
    <?php
}

add_action( 'load-index.php', 
    function(){
        add_action( 'admin_notices', 'my_admin_notice' );
    }
);

where we use the load-index.php hook to target the dashboard page.

Leave a Comment