另一种方法是使用load-{$page}
钩
示例:
add_action(\'load-edit.php\', \'maybe_edit_notice\'); // only on edit.php paged
function maybe_edit_notice() {
// some example notices based on the get variables
// the url should be something htt://example.com/wp-admin/edit.php?done=1&error=1
if ( isset($_GET[\'done\']) ) {
$message = isset($_GET[\'error\']) ? \'There was an error.\' : \'Everithing ok.\';
$class = isset($_GET[\'error\']) ? \'error\' : \'updated\';
global $my_notice_args;
$my_notice_args = compact(\'message\', \'class\');
add_action(\'admin_notices\', \'print_my_notice\');
}
}
function print_my_notice() {
global $my_notice_args;
if ( ! empty($my_notice_args) ) {
printf(\'<div class="%s"><p>%s</p></div>\', $my_args_notice[\'class\'], $my_args_notice[\'message\']);
}
}
请参见
\'admin_notices\' hook docs 关于Codex