I am trying to display a notice in admin panel when I activate my test plugin.
How can I display that? What’s that method?
Leave a Reply
You must be logged in to post a comment.
I am trying to display a notice in admin panel when I activate my test plugin.
How can I display that? What’s that method?
You must be logged in to post a comment.
For plugin activations, the ‘admin_notices’ hook cannot be used directly, because there is a redirect. A workaround is to store your notice in the options table and check for it next time. Also, if you also want to cover plugin upgrades as well as activations, you will need to use another hook, such as ‘admin_init’ (since WP 3.1, see http://make.wordpress.org/core/2010/10/27/plugin-activation-hooks/).
Here is a complete sample plugin handling both activation and upgrade. I made the deferred notice an array so you can stack them up.
UPDATE: There’s also a common way to use
set_transient()
instead ofupdate_option()
, and to direct messages to the correct admin user. This post concerns metaboxes, not plugin activation, but the techniques work the same just about everywhere in Dashboard, as far as I know: https://wordpress.stackexchange.com/questions/15354/passing-error-warning-messages-from-a-meta-box-to-admin-noticesThis is so simple to show a notice
But if you want to show a Dismissible Notice then try below
And if you want to show that notice on certain page try below condition.
You can see here
Just use a
<div class='updated'>
. For example –You can use the new admin notices to create what are called admin pointers using
show_wp_pointer_admin_bar
.Linky: http://wpengineer.com/2272/how-to-add-and-deactivate-the-new-feature-pointer-in-wordpress-3-3/
The proper way to add your notices is to echo it in your hook for
admin_notices
action:I’ve developed amarkal-admin-notification – a script that lets you add static/dismissible admin notices and handles the dismissal for you. This script is a module within the Amarkal WordPress framework.
For example: